If you want to find the commits that touched a specific text in a file,
use git log -S 'text in the code' -- path/to/file
.
Here is an example, where the move of the convert_number_column_value(value)
method in active record is traced (simplified output):
https://makandracards.com/makandra/42705-git-show-commits-that-have-touched-specific-text-in-a-file
-S<string>
Look for differences that change the number of occurrences of the specified string (i.e. addition/deletion) in a file. Intended for the scripter’s use.
It is useful when you’re looking for an exact block of code (like a struct), and want to know the history of that block since it first came into being: use the feature iteratively to feed the interesting block in the preimage back into -S
, and keep going until you get the very first version of the block.
Binary files are searched as well.
-G<regex>
Look for differences whose patch text contains added/removed lines that match <regex>.
To illustrate the difference between -S<regex> --pickaxe-regex
and -G<regex>
, consider a commit with the following diff in the same file:
+ return !regexec(regexp, two->ptr, 1, ®match, 0); ... - hit = !regexec(regexp, mf2.ptr, 1, ®match, 0);
While git log -G"regexec\(regexp"
will show this commit, git log -S"regexec\(regexp" --pickaxe-regex
will not (because the number of occurrences of that string did not change).
Unless --text
is supplied patches of binary files without a textconv filter will be ignored.
See the pickaxe entry in gitdiffcore[7] for more information.
https://git-scm.com/docs/git-log