Investigate Line History with Git Blame
Attribute a line, not fault
Blame maps surviving lines in a selected snapshot to revisions that last changed them under its matching rules. It is not a list of everyone who ever edited the file and cannot establish responsibility for a bug. In the history fixture h0 adds three lines, h1 changes the watering number, h2 adds a footer, h3 renames notes.txt to garden.txt. A teammate can inherit bad design, apply a requested change, or merely format a line. Inspect context respectfully.
git blame -L 2,2 -- garden.txtgit show h1 -- notes.txtChoose the snapshot
Line numbers are relative to the selected snapshot. In h0 line 2 is Water every 3 days; h1 changes it to Water every 2 days. At HEAD after a pure rename, blame follows the whole-file rename and attributes that line to h1. Compare a historical snapshot to understand what changed, not merely who last touched the current line.
git blame -L 2,2 h0 -- notes.txtgit blame --line-porcelain -L 2,2 HEAD -- garden.txtKnow matching limits
The --line-porcelain format is useful for tooling and provides per-line metadata. Whitespace-only changes can be ignored with -w; -M and -C request additional move/copy detection, which is heuristic and may need tuning. These options are not a guarantee of origin; the lab verifies ordinary whole-file rename attribution, not all copy detection. Deleted lines do not appear in current blame; use patch history for them.
Practice an evidence-based investigation
Find the commit attributed to line 2, inspect the commit diff and compare its parent. In the fixture h1 changes the number, h2 adds a separate footer and h3 renames the file. Explain why the current line is not attributed to h3. Then identify the footer origin separately.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Investigate Line History with Git Blame — knowledge check
Reason about regression and historical evidence.
What does blame attribute?
Which revision owns current line 2 in the fixture?
What does -L 2,2 select?
What helps inspect deleted lines?
How should an attribution be used?