git blame
Find out who last modified every line of a file
Practical example
git blame src/index.ts # annotate every line git blame -L 15,30 src/app.ts # lines 15-30 only git blame -w -C src/index.ts # ignore whitespace, detect moved lines
Command overview & how it works
Annotates each line of a file with the commit hash, author name, and timestamp of the most recent modification. This is the go-to command when you need to understand why a particular line of code exists — it tells you who wrote it, when, and in which commit. Use git blame -L 10,20 file.ts to limit output to a specific line range, or git blame -w to ignore whitespace changes. Use git blame -C to detect lines that were copied from other files (even within different files in the same commit). Combined with git show <hash>, you can trace any line of code back to its original context, commit message, and related changes. This is especially useful during debugging, code review, and refactoring legacy code.
Master Git log, diff, and blame offline
Read advanced graph traversals, patch analysis, and investigation workflows in the 97-page offline course — ₹499.
Practical tips
- Pair git blame with git show <hash> to read the commit message behind a line of code.
- Limit output to the lines you care about with git blame -L 10,30 file.ts.
- Use -w to ignore whitespace-only changes and -C to follow lines that moved between files.
Deep-dive guides & tutorials
In-depth walkthroughs and practical scenarios related to git blame
- Tutorial
Git Log Formats: Customize Your History Output
Master git log with custom formats, filters, and graph views. Learn the format placeholders that turn raw history into a readable, useful log.
7 min readRead guide - Tutorial
Git Diff: Compare Changes Across Commits and Branches
See exactly what changed between commits, branches, or your working directory. Master git diff for thorough code reviews.
5 min readRead guide - Tutorial
Git Blame: Track Changes Back to Their Author
Use git blame to find who last modified every line of a file. Essential for code review, debugging, and understanding project history.
4 min readRead guide
Related commands
More from Inspecting History