# git blame Command: Attribute Lines in CI

> git blame shows which commit last changed each line. Reference for -L, --porcelain, and -w to attribute lines in code-owner and audit CI checks.

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

git blame annotates each line of a file with the commit and author that last modified it.

Audit and ownership automation uses blame to find who last touched a line or when a pattern was introduced. The porcelain format makes its output machine-readable.

## Common flags

- `-L <start>,<end>` - restrict blame to a line range
- `--porcelain` - stable, parseable output with full commit metadata
- `-w` - ignore whitespace changes when assigning blame
- `-C` / `-M` - detect lines moved or copied within or across files
- `--since=<date>` - limit blame to commits after a date
- `-l` - show full (long) commit SHAs

## Example

```shell
# Who last changed a specific config line?
git blame -L 42,42 --porcelain config/app.yaml | head -n1
```

## In CI

Use --porcelain when scripting blame so the output format is stable across Git versions. -w avoids misattributing lines to a reformatting commit. blame reads history, so it needs enough depth; a too-shallow clone yields "Not Committed Yet" or incomplete attribution.

## 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 Command: Attribute Lines in CI?

Audit and ownership automation uses blame to find who last touched a line or when a pattern was introduced. The porcelain format makes its output machine-readable.

### In CI?

Use --porcelain when scripting blame so the output format is stable across Git versions. -w avoids misattributing lines to a reformatting commit. blame reads history, so it needs enough depth; a too-shallow clone yields "Not Committed Yet" or incomplete attribution.

---

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
