Skip to content
Search

Git:Grep

lastmod 2020-11-16created 2020-11-163 edits

How to grep in git.

Examples

git grep<regexp>
Search the working tree for text matching the regular expression regexp:
git grep<regexp>$(git rev-list --all)
To search commit contents (i.e., the actual source lines, as opposed to commit messages), you need to do the following.
git grep<regexp>$(git rev-list --all -- lib/util) -- lib/util
Limit the search to some subtree.
git grep -e<regexp1>[--or] -e<regexp2>
Search the working tree for lines of text matching the regular expression regexp1 or regexp2.
git grep -e<regexp1>--and -e<regexp2>
Search the working tree for lines of text matching the regular expressions regexp1 and regexp2, and report only the file paths.
git grep -l --all-match -e<regexp1>-e<regexp2>
Search the working tree for files that have lines of text matching the regular expression regexp1 and lines of text matching the regular expression regexp2.
git diff --unified=0 | grep<pattern>
Search the working tree for changed lines of text matching the pattern:
git grep<regexp>$(git rev-list --all)
Search all revisions for text matching the regular expression regexp.
git grep<regexp>$(git rev-list<rev1>..<rev2>)
Search all revisions between rev1 and rev2 for text matching the regular expression regexp.

See also

Favorite site

author Zer0 sitemap