man*_*lds 144
你可以在Git仓库上做到这一点:
git grep "string/regexp" $(git rev-list --all)
Run Code Online (Sandbox Code Playgroud)
Github高级搜索具有代码搜索功能:
代码搜索将查看GitHub上公开托管的所有代码.您还可以按以下方式过滤:
language:
repo:
path:
tea*_*urn 108
如果您使用@manojlds git grep命令并收到错误:
-bash: /usr/bin/git: Argument list too long"
Run Code Online (Sandbox Code Playgroud)
那么你应该使用xargs:
git rev-list --all | xargs git grep "string/regexp"
Run Code Online (Sandbox Code Playgroud)
另请参阅如何在git历史记录中grep(搜索)已提交的代码?
Zit*_*rax 43
在许多情况下,git rev-list --all
可以返回大量的提交,永远扫描.如果您不是在存储库历史记录中的每个分支上搜索每个提交,而只想搜索所有分支提示,则可以将其替换为git show-ref --heads
.所以总的来说:
git grep "string" `git show-ref --heads`
Run Code Online (Sandbox Code Playgroud)
要么:
git show-ref --heads | xargs git grep "string"
Run Code Online (Sandbox Code Playgroud)
提示:您可以在文件中编写输出以在编辑器中查看.
nano ~/history.txt
git show-ref --heads | xargs git grep "search string here" >> ~/history.txt
Run Code Online (Sandbox Code Playgroud)
Vic*_*hoy 15
你可以试试这个:
git log -Sxxxx # Search all commits
git log -Sxxxx --branches[=<pattern>] # Search branches
Run Code Online (Sandbox Code Playgroud)
hIp*_*pPy 13
这里列出的解决方案几乎没有问题(甚至被接受).
它建立在这个地方,你可以搜索字符串"test -f /"
的多个分支master
,并dev
作为
git grep "test -f /" master dev
Run Code Online (Sandbox Code Playgroud)
与...相同
printf "master\ndev" | xargs git grep "test -f /"
Run Code Online (Sandbox Code Playgroud)
所以这里.
这将查找所有本地分支的提示的哈希值,并仅在这些提交中进行搜索.
git branch -v --no-abbrev | awk -F' *' '{print $3}' | xargs git grep "string/regexp"
Run Code Online (Sandbox Code Playgroud)
如果您还需要在远程分支中搜索,请添加-a
:
git branch -a -v --no-abbrev | awk -F' *' '{print $3}' | xargs git grep "string/regexp"
Run Code Online (Sandbox Code Playgroud)
更新:
# Search in local branches
git branch | cut -c3- | xargs git grep "string"
# Search in remote branches
git branch -r | cut -c3- | xargs git grep "string"
# Search in all (local and remote) branches
git branch -a | cut -c3- | cut -d' ' -f 1 | xargs git grep "string"
# Search in branches, and tags
git show-ref | grep -v "refs/stash" | cut -d' ' -f2 | xargs git grep "string"
Run Code Online (Sandbox Code Playgroud)
小智 5
按照@peter-mortensen & manojlds的解决方案,我使用git for-each-ref
作为子命令仅列出具有名称的分支。
git grep "string/regexp" $(git for-each-ref --format='%(refname:short)' refs/heads)
Run Code Online (Sandbox Code Playgroud)
这实现了更好的可视化,仅显示命名分支并为每个分支仅生成一个结果。
归档时间: |
|
查看次数: |
46458 次 |
最近记录: |