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 -n1In 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
git log Command: Inspect History in CIgit log shows commit history. Reference for --oneline, -n, and --format to extract commit messages and author…
git show Command: Inspect Objects in CIgit show displays commits, tags, and file contents at a revision. Reference for printing a commit message or…
git shortlog Command: Summarize Authors in CIgit shortlog groups commits by author. Reference for -s, -n, and ranges to build contributor summaries and re…
git diff Command: Detect Changes in CIgit diff shows changes between commits or the working tree. Reference for --name-only, --stat, and --exit-cod…