pvinis
pvinis

Reputation: 4139

Look at git blame but also previous git blames of the same line

Many times I look at a line and see the blame for it. Then I get something like "fixed indentation".
I would like to be able to go one commit before that indentation fix, and see the blame for that line again.
Does that make sense? Can I do that somehow, without doing the checkout, blame again manually?

Upvotes: 3

Views: 623

Answers (3)

Andy Ray
Andy Ray

Reputation: 32076

This isn't an answer to your question, but it's a general git tip: You shouldn't use git blame to find out who changed lines. Things like moving/renaming files, fixing indentation, etc, will show the "wrong" person as the author of the line in question. In my experience on large projects git blame is wrong most of the time.

The most effective method I've found to find the "right" author of a change (someone who wrote the code / changed its logic, not a cosmetic one), is to run at the command line:

git log -p -- path/to/file
  • -p patch show the changes to the file for each commit
  • -- file (note space before and after) only for specified file

Then search the output (using /, enter the pattern, then press n to jump to the next match) for part of the line in question. Then you can scroll up to see the commit and the author you're looking for.

Upvotes: 1

max630
max630

Reputation: 9248

Blame built in GUI programs often provide an option to blame further starting from the parent of found commit. For example git gui blame $file has such item in context menu for a line. What I like even more is "Find origin of this line" command in gitk - it's more focused on what I really want to get. Then if necessary I run it again on the older line in the found diff.

Upvotes: 1

Melebius
Melebius

Reputation: 6695

It’s definitely possible. Let’s say the hash of your useless commit is abcdef1. Then its parent (previous commit) can be accessed using abcdef1~1. So to blame the commit before abcdef1, run:

git blame abcdef1~1 file.txt

Upvotes: 4

Related Questions