How to See Who Changed a File in Git: Simple Commands
Use
git blame <file> to see line-by-line who last changed each part of a file. Alternatively, use git log --follow <file> to view the full history of changes and authors for that file.Syntax
git blame <file>: Shows the last commit and author for each line in the file.
git log --follow <file>: Lists all commits that changed the file, including renames.
bash
git blame <file>
git log --follow <file>Example
This example shows how to find who last changed each line of README.md and how to see the full commit history for it.
bash
git blame README.md
git log --follow README.mdOutput
commit 1a2b3c4d5e6f7g8h9i0j
Author: Jane Doe <jane@example.com>
Date: 2024-06-01
Update README with usage instructions
...
commit 0j9i8h7g6f5e4d3c2b1a
Author: John Smith <john@example.com>
Date: 2024-05-20
Initial README creation
...
Common Pitfalls
- Using
git blameon a file that was renamed may not show full history unless--followis used withgit log. - For large files,
git blameoutput can be overwhelming; consider limiting lines or using GUI tools. - Confusing
git blameoutput with the entire file history; it only shows the last change per line.
bash
git blame oldname.txt # May miss history if file was renamed git log --follow oldname.txt # Correct way to track history across renames
Quick Reference
| Command | Purpose |
|---|---|
| git blame | Show last author and commit per line in the file |
| git log --follow | Show full commit history including renames |
| git show | See details of a specific commit |
| git diff | See changes between commits for the file |
Key Takeaways
Use git blame to see who last changed each line of a file.
Use git log --follow to see the full history of a file including renames.
git blame shows only the last change per line, not full history.
For renamed files, always use --follow with git log to track history.
Check specific commits with git show for detailed change info.