Skip to main content
Back to blog
Git Blame: Track Changes Back to Their Author — Tutorial
Tutorial4 min read

Git Blame: Track Changes Back to Their Author

What Git Blame Does

git blame annotates every line of a file with the commit hash, author, and date of the last modification. It answers: "Who changed this line, and when?"

bash
git blame src/server.ts

Output:

bash
abc1234 (Alice  2024-03-15) const API_URL = "https://api.example.com";
def5678 (Bob    2024-04-01) const timeout = 5000;
ghi9012 (Alice  2024-05-10) function fetchData() {

Practical Uses

Find who introduced a bug:

bash
git blame src/auth.ts
# Find the line with the bug, note the commit hash
git show abc1234

Understand why code exists:

Sometimes the blame output points to a commit whose message explains the reasoning behind a seemingly odd line of code.

Useful Options

bash
# Blame a specific range of lines
git blame -L 30,50 src/utils.ts

# Show the raw commit contents alongside blame
git blame -s src/config.ts

# Ignore whitespace changes
git blame -w src/styles.css

# Follow file renames
git blame -C src/refactored.ts

Blame Etiquette

Blame finds responsibility, not fault. A commit that introduced a bug was a best-effort change at the time. Use blame to understand and collaborate, not to assign blame in the accusatory sense.

Combining with Other Commands

bash
# Blame + log for full context
git blame src/app.ts | grep "TODO"
git log --oneline -5 -- src/app.ts

git blame is a forensic tool for understanding the evolution of your codebase, one line at a time.

Chapter 08 · History & Diff Mastery

Master Git log, diff, and blame offline

Read advanced graph traversals, patch analysis, and investigation workflows in the 97-page offline course — ₹499.

Learn more

Related Git Command References

All 28 commands →

Syntax breakdowns and practical terminal examples for commands used in this topic

More on History & Diff Inspection

All articles →