搜索git使用Regex提交

moe*_*oey 22 regex git command-line

我有一个git存储库,包含数百个提交和几个分支.如何搜索包含某个字符串的特定提交,例如"辅助函数"?理想情况下,字符串可以用正则表达式表示.

kni*_*ttl 22

较新版本的git支持git log -G<regex>:

git log -G'helper.*function' --full-history --all
Run Code Online (Sandbox Code Playgroud)

它将在每次提交的diff中搜索正则表达式,并且只显示引入了与正则表达式匹配的更改的提交.


moe*_*oey 20

积分转到这个答案:

git log --all --grep='Build 0051'

# case insensitive
git log --all --grep='Build 0051' -i
Run Code Online (Sandbox Code Playgroud)

  • 这会在提交消息中查找正则表达式,而不是 knittl 的答案,其中 -G&lt;regex&gt; 搜索提交的差异。 (3认同)