42

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.

1

2 Answers 2

48

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This was the answer I was looking for, and how I understood the question was written.
35

Credits go to this answer:

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

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

1 Comment

This looks for the regex in the commit message as opposed to knittl's answer, where -G<regex> searches through the commit's diff.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.