简体   繁体   English

搜索git使用Regex提交

[英]Search git Commits Using Regex

I have a git repository that contains hundreds of commits and several branches. 我有一个git存储库,包含数百个提交和几个分支。 How to search a particular commit that contains a certain string eg "helper function"? 如何搜索包含某个字符串的特定提交,例如“辅助函数”? Ideally, the string can be denoted by a regex. 理想情况下,字符串可以用正则表达式表示。

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. 它将在每次提交的diff中搜索正则表达式,并且只显示引入了与正则表达式匹配的更改的提交。

Credits go to this answer : 积分转到这个答案

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

# case insensitive
git log --all --grep='Build 0051' -i

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM