Tech AI Insights

Git Blame: Find Who Changed What

Ever wondered who last modified a specific line in a file? The git blame command helps you track changes, showing who made the change, when, and in which commit.

Basic Usage

To see the history of changes in a file, run:

git blame filename.txt

This shows:

  • Commit hash
  • Author name
  • Timestamp
  • Line of code

Example output:

 

a1b2c3d (Alice 2024-02-20) Initial commit
e5f6g7h (Bob   2024-02-22) Updated function logic

Useful Options

Blame Specific Lines

Check only certain lines (e.g., 10 to 20)

git blame -L 10,20 filename.txt

Ignore Whitespace Changes

Avoid unnecessary blame due to formatting:

git blame -w filename.txt

See Blame Before a Commit

Find how a file looked before a change:

git blame <commit>^ -- filename.txt

Track Changes Across Renames

If a file was renamed, follow its history:

git blame -C filename.txt

When to Use git blame

✔ Debugging – Find out who introduced a bug.
✔ Code Reviews – Check recent changes.
✔ Documentation – Ask the right person for help.

Tip: Use git blame to learn, not to point fingers!

Scroll to Top