🌞


Note that this blog post has been archived. Information may be out of date or incorrect.

Searching your Git history for a string or regular expression

Git seems to always have the feature I need, but often I’m not able to find it right away. While searching for a commit where a certain constant had been removed, I stumbled upon the deprecated git-diff-grep, which, in its readme, led me to the solution I could have easily found by just reading the, you know, manual (i.e. man git-log) :)

-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.

-G<regex>
    Look for differences whose added or removed line matches the given
    <regex>.

Knowing that, you can simply do the following:

:bash:
$ git log -S"WHERE_DID_IT_GO"
$ git log -G"WHERE_DID.*"

If you want to see the commit’s diff as well, just supply the -p option.