How to use git blame to find who changed a line
· Category: Git
Short answer
git blame <file> shows the commit and author for each line in the file.
Steps
- Blame a file:
git blame src/app.py
- Blame specific lines:
git blame -L 10,20 src/app.py
- Ignore whitespace changes:
git blame -w src/app.py
- Show email instead of name:
git blame -e src/app.py
Tips
- Use with
git show <commit>to see the full change context. git blameon renamed files works with-Cand-Moptions.- IDE integrations often provide blame annotations inline.
Common issues
- Large refactoring commits make blame less useful; use
-Cto detect moved lines. - Blame shows the last change, not every historical change to that line.