Thursday, July 4, 2013

Search through the GIT history like a ninja

To search for regexp through the whole GIT history you should to execute:

git grep <regexp> $(git rev-list --all)

 This will grep through all your commit text for regexp.

Here are some other useful ways of searching your source:

- 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>

-Search working tree for files that have lines of text matching regular expression regexp1 and lines of text matching regular expression regexp2:

git grep -l --all-match -e <regexp1> -e <regexp2>

-Search all revisions for text matching regular expression regexp:

git grep <regexp> $(git rev-list --all)


-Search all revisions between rev1 and rev2 for text matching regular expression regexp:

git grep <regexp> $(git rev-list <rev1>..<rev2>)

If you have a git l alias to pretty log output, you can run this to search for commits whose changes include your regexp:

git l -G <regexp>
 

No comments:

Post a Comment