Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I search a word in Git repo over the whole history?

Tags:

git

Suppose I remember that I saved a word "XYZword" to some file in a repo but it got killed and I can only remember the initial part "XYZ" but nothing about the time or file. How can I grep this "XYZ" over the whole history?

like image 632
hhh Avatar asked Mar 01 '12 19:03

hhh


2 Answers

To search the full history of the current branch and get the line numbers:

git grep -n "XYZ" $(git rev-list --all)
like image 144
wpgreenway Avatar answered Nov 13 '22 07:11

wpgreenway


git log -S[SOME_WORD_OR_REGEX] will search your history for any changes that contain the word or regex you supplied. For more information, check out the pickaxe entry in gitdiffcore(7).

like image 43
jbowes Avatar answered Nov 13 '22 05:11

jbowes