Finding content inside your repository
Sometimes, you will need to find something inside all your files. You can, of course, find it with the search feature of your OS, but Git already knows all your files.
Searching file content
To search text inside your files, simply use the following command:
Erik@server:~$ git grep "Something to find" Erik@server:~$ git grep -n body Master:Website.Index.html:4: <body> Master:Website.Index.html:12: </body>
It will display every match to the given keyword inside your code. All lines use the [commitref]:[filepath]:[linenumber]:[matchingcontent]
pattern.
Note
Notice that [commitref]
isn't displayed on all Git versions.
You can also specify the commit references that grep
will use to search the keyword:
Erik@server:~$ git grep -n body d32lf56 p88e03d HEAD~3 Master:Website.Index.html:4: <body> Master:Website.Index.html:12: </body>
In this case, grep
will look into the d32lf56
, p88e03d
, and third commit starting...