Hone

Lessons · Git · who last changed this line

Who changed this line, and why

git blame file shows, for each line, the commit and author that last changed it. The hash leads to the message, which is where the why lives.

Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.

What it is for

The fastest route from a puzzling line to the reasoning behind it. Not for blame in the human sense: for context.

How to think about it

Blame the file, limit to the lines you care about with -L, then git show the hash. If the last change was a reformat, -w ignores whitespace and git log -L follows the line's real history.

Worked example

git blame a.txt
Each line with the commit and author that last touched it.
git blame -L 3,5 a.txt
Only lines 3 to 5.
git show a1b2c3d
The commit blame named: the why, if the message was written well.

Your turn

Blame only lines 10 to 20.

git blame  10,20 app.py

The trap

Blame names the last change, which is often a reformat or a rename. Use -w to skip whitespace changes and git log -L to find the real author.

Practise who last changed this line on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.