Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git blame -- prior commits?

Tags:

git

commit

blame

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?

like image 514
Sedate Alien Avatar asked Feb 23 '11 22:02

Sedate Alien


People also ask

Does git blame identify a particular commit?

The git blame command is used to know who/which commit is responsible for the latest changes made to a file. The author/commit of each line can also been seen.

Why is it called git blame?

In case you don't know git-blameIf you want to know who last changed a particular chunk of code, you use Git to run a special command. That command is called blame. In other words, you don't ask who the author is, you ask who's to blame for a particular contribution.

How does blame work in git?

The git blame command is used to examine the contents of a file line by line and see when each line was last modified and who the author of the modifications was. The output format of git blame can be altered with various command line options.

How do I git blame on GitHub?

On GitHub.com, navigate to the main page of the repository. Click to open the file whose line history you want to view. In the upper-right corner of the file view, click Blame to open the blame view.


1 Answers

git blame -L 10,+1 fe25b6d^ -- src/options.cpp 

You can specify a revision for git blame to look back starting from (instead of the default of HEAD); fe25b6d^ is the parent of fe25b6d.


Edit: New to Git 2.23, we have the --ignore-rev option added to git blame:

git blame --ignore-rev fe25b6d 

While this doesn't answer OP's question of giving the stack of commits (you'll use git log for that, as per the other answer), it is a better way of this solution, as you won't potentially misblame the other lines.

like image 161
Amber Avatar answered Sep 19 '22 15:09

Amber