在Git远程所有分支中搜索文件内容 [英] Search Git remote all branches for file contents
本文介绍了在Git远程所有分支中搜索文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在我的所有Git远程分支中搜索特定的文件内容(不仅是文件,还包括其中的内容)?
Is it possible to search all of my Git remote branches for specific file contents (not just a file, but contents within them)?
我的遥控器在GitHub上,以防万一...
My remotes are on GitHub, in case that helps...
推荐答案
您可以尝试以下操作:
git grep 'search-string' $(git ls-remote . 'refs/remotes/*' | cut -f 2)
这将在所有远程分支中搜索search-string
.由于符号引用HEAD
已镜像,因此您可能最终会搜索相同的提交两次.希望这不是问题.如果是这样,您可以使用以下方法将其过滤掉:
That will search all remote branches for search-string
. Since the symbolic reference HEAD
is mirrored, you may end up searching the same commit twice. Hopefully that's not an issue. If so, you can filter it out with:
git grep 'search-string' \
$(git ls-remote . 'refs/remotes/*' | grep -v HEAD | cut -f 2)
如果您需要浏览整个历史记录,还可以尝试:
If you need to dig through your entire history, you can also try:
git grep 'search-string' $(git rev-list --all)
这篇关于在Git远程所有分支中搜索文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文