All commands

git blame

intermediate

Attribute every line of a file to the commit and author that made it.

What 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.'

@@ -1,3 +1,3 @@ src/App.tsxMyers diff → edit script
const header = 'OLD'
const header = 'NEW'
const nav = [ 'home', 'about' ]
const nav = [ 'home', 'about', 'blog' ]
return <div>
return <div>

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.

1 / 2

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.ts
@@ -1,3 +1,3 @@ src/App.tsxMyers diff → edit script
const header = 'OLD'
const header = 'NEW'
const nav = [ 'home', 'about' ]
const nav = [ 'home', 'about', 'blog' ]
return <div>
return <div>

Every line now wears its origin commit

Under the hood

1

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
2

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.

Command anatomy

git blame <file>
-L <start>,<end>

Only blame a line range (fast for large files).

-M

Detect lines moved within the same file.

-C

Detect lines copied from other files.

-w

Ignore 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.

Practice

A real repo, pre-seeded with history, runs right here — stage, commit, branch, stash, diff, even hit and resolve a real merge conflict. Nothing to install, nothing leaves your machine.

Open practice playground

Go deeper with