Skip to content
LatchkeyLatchkey home

git blame Command: Attribute Lines in CI

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

Key takeaways

  • git blame --porcelain gives stable, parseable line attribution for audit scripts.
  • -w prevents whitespace-only commits from stealing the blame.
  • It needs real history, so deepen shallow clones before blaming.

Frequently asked questions

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.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card