kfmfe04
kfmfe04

Reputation: 15337

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

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.

Upvotes: 5

Views: 96

Answers (1)

Zombo
Zombo

Reputation: 1

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.

Upvotes: 4

Related Questions