# git blame: Usage, Options & Common CI Errors

> git blame shows which commit and author last changed each line of a file. Reference for -L, -C, --since, and missing-history errors on shallow clones.

Source: https://latchkey.dev/learn/command-reference/git-blame  
Updated: 2026-06-25

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@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
```

> `git rev-parse --abbrev-ref HEAD` returns the literal string `HEAD` on a detached checkout rather than a branch name. On GitHub Actions read `github.ref_name` instead; the git command cannot know what it was checked out for.

## FAQ

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

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
