我可以使用Git在存储库中搜索匹配的文件名吗

我可以使用Git在存储库中搜索匹配的文件名吗

本文介绍了我可以使用Git在存储库中搜索匹配的文件名吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想发出一个命令来查找完整的路径所有匹配HelloWorld.pm的文件:



例如:

  /path/to/repository/HelloWorld.pm 
/path/to/repository/but/much/deeper/down/HelloWorld.pm
/ path / to / repository / please / dont / make / me / search / through / the / lot / HelloWorld.pm

如何使用Git高效地找到所有匹配给定文件名的完整路径?



我意识到我可以用Linux / Unix find命令来做到这一点,但我希望避免扫描所有子目录例如文件名称。

解决方案

会给你列出所有文件存储库。您可以传入一个模式来获取匹配该模式的文件。

  git ls-files'* / HelloWorld.pm'

如果您想通过其内容找到一组文件和grep,可以使用:

  git grep some-string  - '* / HelloWorld.pm'


Just say I have a file: "HelloWorld.pm" in multiple subdirectories within a Git repository.

I would like to issue a command to find the full paths of all the files matching "HelloWorld.pm":

For example:

/path/to/repository/HelloWorld.pm
/path/to/repository/but/much/deeper/down/HelloWorld.pm
/path/to/repository/please/dont/make/me/search/through/the/lot/HelloWorld.pm

How can I use Git to efficiently find all the full paths that match a given filename?

I realise I can do this with the Linux/Unix find command but I was hoping to avoid scanning all subdirectories looking for instances of the filename.

解决方案

git ls-files will give you a listing of all files in the repository. You can pass a pattern in to get files matching that pattern.

git ls-files '*/HelloWorld.pm'

If you would like to find a set of files and grep through their contents, you can do that with git grep:

git grep some-string -- '*/HelloWorld.pm'

这篇关于我可以使用Git在存储库中搜索匹配的文件名吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 08:27