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 revision
Options
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.
Using this in CI
CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.
.github/workflows/ci.yml
- uses:actions/checkout@v4with:fetch-depth:0 # history, tags, and git describe all need this- run:|git rev-parse --is-shallow-repository # expect falsegit rev-parse --abbrev-ref HEAD # prints HEAD when detached
Frequently asked questions
git blame: Usage, Options & Common CI Errors?
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 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.