Day 42beginnerMar 14, 2026

Trace Every Line's Author with Git Blame

Git blame reveals who changed each line and why, turning mysterious code into a story you can follow.

gitdebuggingcollaboration
Share:

What

git blame shows who last modified each line of a file and when. It annotates every line with the commit SHA, author, and timestamp. Combined with git log, it helps you understand the history and context behind code changes β€” not to assign fault, but to find the right person to ask questions.

Why It Matters

When you encounter confusing code, knowing who wrote it and when tells you whether it was intentional, a quick fix, or part of a larger refactor. Blame helps you find the commit message that explains the reasoning. It's an essential debugging and onboarding tool for understanding unfamiliar codebases.

Example

# Blame an entire file
git blame src/app.js

# Blame a specific line range (lines 10-20)
git blame -L 10,20 src/app.js

# Ignore whitespace changes
git blame -w src/app.js

# Show the commit that introduced a specific string
git log -p -S "function_name" -- src/app.js

# Show blame before a specific commit (trace deeper history)
git blame <commit>^ -- src/app.js
bash

Common Mistake

Using blame to assign fault rather than understand context. Blame is a knowledge tool, not a finger-pointing tool. The last person to touch a line may have only reformatted it β€” the real author could be several commits back.

Quick Fix

Use git blame -w to ignore whitespace-only changes, which filters out reformatting commits. For deeper history, use git log -p -S "search_term" to find when a specific piece of code was introduced, not just last modified.

Key Takeaways

  • 1git blame <file> shows who last modified each line
  • 2git blame -L 10,20 <file> blames a specific line range
  • 3git blame -w ignores whitespace changes
  • 4git log -p -S "term" finds when code was introduced
  • 5Use blame for context, not for assigning fault

Was this tip helpful?

Help us improve the DevOpsPath daily collection

Share: