Reputation: 115
I would like to find out all the authors that have changed a line of code. Git-log can do it on the file level. I read the man page and it seems like git log cannot do it on the line level. Is there a way to use git command to do it or I need to write a script for myself?
For my purpose, I would like to do this to all lines of code. I am doing this to produce authorship training data for my research.
Upvotes: 5
Views: 1752
Reputation: 44234
You want to combine the -S
and --pretty
flags on git log
.
From the git log
man page, the -S
pickaxe search:
-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.
This flag looks for all changes to a particular string. Using an example from another SO answer, git log -g -Ssearch_for_this
would search the history for all changes to "search_for_this".
Combine it with --pretty
to get better results. For example, this command would search through the history for changes to 'foo' and return the shortened hash, followed by the author, two dashes, the first line of the message, two dashes, and the date:
$ git log -Sfoo --pretty=format:'%h %an -- %s -- %ad'
bc34134 Sally Developer -- Fixed all bugs and made all clients happy forever -- Tue Jan 31 17:41:17 2025 -0500
Upvotes: 3