Synopsis
git blame [-L <range>] [-w] [-M] [-C] <file>
Description
The git blame command annotates each line of a file with the commit, author, and timestamp that last touched it. It is invaluable for understanding why a piece of code looks the way it does, who introduced it, and when. Despite the accusatory name, blame is mostly used as a research tool, not as a means of finger-pointing.
Blame can follow code as it was moved or copied (with -M and -C), and can ignore whitespace-only or formatting-only commits if you maintain a .git-blame-ignore-revs file referenced via blame.ignoreRevsFile.
In day-to-day use, git blame integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git blame --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.
Understanding how git blame interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git blame's side effects helps avoid all three.
Common Options
| Option | Description |
|---|---|
-L <start>,<end> | Restrict blame to a line range. |
-w | Ignore whitespace changes. |
-M | Detect lines moved within a file. |
-C | Detect lines copied from other files (repeat for stronger detection). |
--since=<date> | Stop annotating earlier than this date. |
-e, --show-email | Show author email instead of name. |
--ignore-revs-file <file> | Skip listed revisions when assigning blame. |
Examples
git blame src/parser.c
# Annotate every line
git blame -L 50,100 src/parser.c
# Just lines 50 through 100
git blame -w -M -C README.md
# Ignore whitespace and detect moves/copies
git blame --ignore-revs-file .git-blame-ignore-revs file.js
# Skip noisy formatting commits
Common Mistakes
Using blame to assign fault rather than to investigate context creates a hostile culture. Pair blame with git log on the offending commit to read the full message and intent. After mass formatting, set up .git-blame-ignore-revs so blame still points to meaningful authors.
Related Commands
git log -L, git log -S, git show, git annotate