Skip to content
LatchkeyLatchkey home

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 revision

Options

FlagWhat it does
-L <start>,<end>Limit to a line range
-C / -MDetect copied / moved lines
-wIgnore whitespace changes
--since=<date>Limit how far back to look
-e / --show-emailShow 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@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git 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.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card