git blame: Usage, Options & Common CI Errors
git blame annotates every line of a file with the commit that last touched it.
Blame answers "who changed this line and when". It needs full history, so shallow clones break it.
What it does
git blame walks history to attribute each line of a file to the commit, author, and time that last modified it.
Common usage
Terminal
git blame file.txt
git blame -L 10,20 file.txt # only lines 10-20
git blame -C -C file.txt # detect moved/copied lines
git blame <rev> -- file.txt # blame as of a revisionOptions
| Flag | What it does |
|---|---|
| -L <start>,<end> | Limit to a line range |
| -C / -M | Detect copied / moved lines |
| -w | Ignore whitespace changes |
| --since=<date> | Limit how far back to look |
| -e / --show-email | Show author email instead of name |
Common errors in CI
On a shallow clone, blame shows the boundary commit (often the single fetched commit) for most lines because the deeper history is missing. Set fetch-depth: 0 (or git fetch --unshallow) so blame can attribute lines correctly.
Related guides
git log: Usage, Options & Common CI Errorsgit log shows commit history with flexible formatting. Reference for --oneline, --graph, --pretty, ranges, an…
git show: Usage, Options & Common CI Errorsgit show displays a commit, tag, or object with its diff. Reference for --stat, --name-only, blob viewing, an…
git fetch: Usage, Options & Common CI Errorsgit fetch downloads remote objects and refs without touching your working tree. Reference for --depth, --unsh…
git diff: Usage, Options & Common CI Errorsgit diff shows changes between commits, the index, and the working tree. Reference for --staged, --name-only,…