Skip to content
Latchkey

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.

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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →