Is it possible to see who edited a specific line before the commit reported by git blame
, like a history of commits for a given line?
For example, I run the following (on the superb uncrustify
project):
$ git blame -L10,+1 src/options.cpp
^fe25b6d (Ben Gardner 2009-10-17 13:13:55 -0500 10) #include "prototypes.h"
How can I find out who edited that line before commit fe25b6d
? And who edited it before that commit?
Build on stangls's answer, I put this script in my PATH (even on Windows) as git-bh:
That allows me to look for all commits where a word was involved:
Script:
If you are using JetBrains Idea IDE (and derivatives) you can select several lines, right click for the context menu, then Git -> Show history for selection. You will see list of commits which were affecting the selected lines:
There's also
recursive-blame
. It can be installed withYou can specify a revision for git blame to look back starting from (instead of the default of
HEAD
);fe25b6d^
is the parent offe25b6d
.Building on the previous answer, this bash one-liner should give you what you're looking for. It displays the git blame history for a particular line of a particular file, through the last 5 revisions:
In the output of this command, you might see the content of the line change, or the line number displayed might even change, for a particular commit.
This often indicates that the line was added for the first time, after that particular commit. It could also indicate the line was moved from another part of the file.
Building on DavidN's answer and I want to follow renamed file:
ref: nicely display file rename history in git log