You can use the -S
or -G
options to git log
. The difference between them is that -S
takes a fixed string (representing the line of code that you want to match), while -G
does the same thing, but takes a regex:
git log --oneline -S 'fixed string'
git log --oneline -G '^foobar$'
The -S
and -G
option will return commits that either first introduce or remove the string/regex pattern. You can even add the --patch
or -p
option if you want to see the diffs with the commit matches.
Documentation
From the official Linux Kernel git log
documentation:
-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>
.