Search in git logs and commit content

Git ships with a command called grep that allows you to easily search through any committed tree or the working directory for a string or regular expression.

Also, git log command has a number of powerful tools for finding specific commits by the content of their messages or even the content of the diff they introduce.

Search in all of the commit messages of project

git log --grep="foo"

Search in commit content (in diffs)

git grep "foo" $(git rev-list --all)

or using 'pickaxe' feature of git log grep,

git log -S"foo"

Using 'pickaxe' feature and show commit content

git log -p -S"foo"

Using 'pickaxe' feature and search over all branches

git log --all -S"foo" 

alternatively, use --branches[=<pattern>] or --tags[=<pattern>].

Search working tree for text matching regular expression regexp

git grep "regexp"

Search working tree for lines of text matching regular expression regexp1 or regexp2

git grep -e regexp1 --or -e regexp2

Search working tree for lines of text matching regular expression regexp1 and regexp2, reporting file paths only:

git grep -e regexp1 --and -e regexp2
comments powered by Disqus