使用正则表达式搜索 git 提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9045435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Search git Commits Using Regex
提问by moey
I have a git repository that contains hundreds of commits and several branches. How to search a particular commit that contains a certain string e.g. "helper function"? Ideally, the string can be denoted by a regex.
我有一个包含数百个提交和几个分支的 git 存储库。如何搜索包含某个字符串的特定提交,例如“辅助函数”?理想情况下,字符串可以用正则表达式表示。
采纳答案by moey
Credits go to this answer:
学分转到这个答案:
git log --all --grep='Build 0051'
# case insensitive
git log --all --grep='Build 0051' -i
回答by knittl
Newer versions of git support git log -G<regex>
:
较新版本的 git 支持git log -G<regex>
:
git log -G'helper.*function' --full-history --all
it will search for the regex in the diff of each commit, and only display commits which introduced a change that matches the regex.
它将在每个提交的差异中搜索正则表达式,并且只显示引入与正则表达式匹配的更改的提交。