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.
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.