31

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.

moey
  • 10,197
  • 23
  • 67
  • 110

2 Answers2

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
  • 1
    This 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
Community
  • 1
  • 1
moey
  • 10,197
  • 23
  • 67
  • 110
  • 4
    This 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