Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: blame the previous version of each line changed in a given commit

For a given commit, I need to run blame on the previous version of each line changed but said commit.

Having a commit that changes lines 2 and 3 on file a, I want a way to see the output of git blame commit^ limited to the preamble and the lines 2 and 3.

How can I do that?

EDIT

Seems like I have to explicitly specify that I'm looking for a way to do the above programmatically, and not examining the commit with my own eyes, determining which lines of which files where changed, and then manually run git blame for each single changed file.

like image 324
giorgian Avatar asked Jun 28 '13 23:06

giorgian


People also ask

Does git blame shows the lines that were deleted or replaced?

The report does not tell you anything about lines which have been deleted or replaced; you need to use a tool such as git diff or the "pickaxe" interface briefly mentioned in the following paragraph.

How do I blame a specific line in git?

Blaming only a limited line range Sometimes, You don't need to blame the entire file, you just need to blame in a limited line range. Git blame provides the option for that. -L will take the option for the start line and for the end line. The above command will blame from line 80 through line 100.

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. There are many other options for blame, but generally these could help.

How Do I Get Out of git blame?

You can also quit the git blame window using the q key on your keyboard. Now, if you want to learn more about what changed in a commit, simply copy the commit hash and use git log as follows. You should be able to see the full commit message, what lines are removed and what lines are added since the commit before it.


1 Answers

You can try:

git blame <commit>^ -- filename | head -3 | tail -2
like image 51
Alessandro Avatar answered Oct 20 '22 15:10

Alessandro