10

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.

giorgian
  • 3,795
  • 1
  • 30
  • 48

1 Answers1

0

You can try:

git blame <commit>^ -- filename | head -3 | tail -2
Alessandro
  • 620
  • 1
  • 5
  • 8
  • 2
    This does not actually do what the question asks -- it simply shows the previous commit, regardless of which lines were changed in this one. See some discussion on why this might be difficult here: http://git.661346.n2.nabble.com/git-blame-and-finding-previous-version-of-a-line-td2363880.html – Arkadiy Kukarkin Jul 14 '14 at 19:52
  • That link is now broken. – Matthias Urlichs Feb 03 '22 at 12:08