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 1.9k times
31
-
6http://stackoverflow.com/questions/2928584/how-to-grep-in-the-git-history – Peter O'Callaghan Jan 28 '12 at 13:07
2 Answers
35
Newer versions of git support 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.
knittl
- 216,605
- 51
- 293
- 340
-
1This was the answer I was looking for, and how I understood the question was written. – Eosis Apr 07 '20 at 09:48
29
Credits go to this answer:
git log --all --grep='Build 0051'
# case insensitive
git log --all --grep='Build 0051' -i
-
4This 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