git blame
intermediateAttribute every line of a file to the commit and author that made it.
git blameWhat it does
git blame walks the commit graph for one file and, line by line, reports which commit (and thus which author and when) last touched that line. It's the forensic tool for 'who wrote this and why.'
Each line carries its origin commit — the effect of blame
Watch it — press play
A narrated, step-by-step walkthrough that shows how to do it — not just theory. It adapts to the learner mode you picked in the top bar.
Step 1
Find the culprit (politely)
git blame walks the file's history backwards and marks every line with the commit that introduced it.
git blame src/main.tsEvery line now wears its origin commit
Under the hood
Backward diff walking
Blame starts at the current version of the file and walks backwards commit by commit, diffing consecutive versions. When an old line disappears from the diff, Git credits the commit that introduced it.
previous blob ──diff──> next blob lines removed leave a mark → attributed to that commit
Renames and splices are tracked
With follow mode (git blame -M -C), Git detects lines copied within a file or across files and re-attributes them to the origin commit — even through renames.
Aliases the pros type
Memorize the git blame concept, then let one of these shortcuts make it instant. Aliases are real git config keys — add one with:
git config --global alias.st # → git blame -Lg blgit blame -LBlame a specific line range you care about.
g blamegit blame -w -MNoise-reduced blame with move detection.
Command anatomy
-L <start>,<end>Only blame a line range (fast for large files).
-MDetect lines moved within the same file.
-CDetect lines copied from other files.
-wIgnore whitespace changes when matching.
When to reach for it
'Why is this line like this?' → blame it, read the message, see the PR.
Finding who last edited a risky function before you touch it.
Code archaeology over 10k-line files, focusing -L on the hot spot.
Pro tip
These days blame is a stepping stone: the second you identify a suspicious commit, jump to its message with `git show <hash>` — the message usually documents exactly why the line exists.