Recent Changes - Search:

Basics

Languages

Tools

OS

Resources

PmWiki

pmwiki.org

edit SideBar

Git /

Grep

Ever wondered what happened to that wonderful piece of code or text you wrote and isn't in the source anymore? After making sure it isn't by looking through the source with Grep, or:

git grep whatYouAreLookingFor

to look through the whole tree for whatYouAreLookingFor. If you know which file to look into, it can be specified with:

git grep whatYouAreLookingFor -- whereYouWantToLookForIt

If it is still missing, you can look in the whole history of the repo with git grep:

git grep whatYouAreLookingFor $(git rev-list --all)

This uses git rev-list --all to provide git grep with the whole list of commits from the history of the repo as further arguments. You can combine both of the above:

git grep whatYouAreLookingFor $(git rev-list --all) -- whereYouWantToLookForIt

By extension1, it is possible to:

Search all revisions between commit1 and commit2 for text:

git grep whatYouAreLookingFor $(git rev-list commit1..commit2)

Note that instances of whatYouAreLookingFor in commit1 will not come up, since rev-list lists the commits that are in the history of commit2 but not in the history of commit1.

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>

All of which can be combined.

1The following content was found on Stack Overflow. Thanks to the original responders!

Edit - History - Print - Recent Changes - Search
Page last modified on July 20, 2016, at 11:48 AM