Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find all git revisions of a file which contains foo?

Tags:

git

Suppose I have a file bar.cpp that I have committed into git. Sometime in the past, I used to have a foo in that file.

QUESTION

How do I find all git revisions of bar.cpp which contain that string foo?

NOTE

A command-line solution would be great.

like image 611
kfmfe04 Avatar asked Oct 03 '22 20:10

kfmfe04


1 Answers

Can use the pickaxe

git log -S foo bar.cpp

and if you want the diffs

git log -p -S foo bar.cpp

More info

-S<string>

    Look for differences that introduce or remove an instance of 
    <string>. Note that this is different than the string simply 
    appearing in diff output; see the pickaxe entry in gitdiffcore(7)
    for more details.
like image 156
Zombo Avatar answered Oct 17 '22 07:10

Zombo