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.
Asked
Active
Viewed 2.3k times
34
-
6http://stackoverflow.com/questions/2928584/how-to-grep-in-the-git-history – Peter O'Callaghan Jan 28 '12 at 13:07
2 Answers
39
Newer versions of Git support git log -G<regex>
:
git log -G'helper.*function' --full-history --all
This command will search for the regex in the diff of each commit, and only display commits which introduced a change that matches the regex.

knittl
- 246,190
- 53
- 318
- 364
-
1This was the answer I was looking for, and how I understood the question was written. – Eosis Apr 07 '20 at 09:48
33
Credits go to this answer:
git log --all --grep='Build 0051'
# case insensitive
git log --all --grep='Build 0051' -i
-
5This looks for the regex in the commit message as opposed to knittl's answer, where -G
searches through the commit's diff. – staafl Jan 16 '18 at 20:09