git show
Show a commit, a tag or a file at a given version
The 'git show' command displays one object. For a commit it prints the author, date and message followed by the diff that commit introduced. For an annotated tag it shows the tag message and then the commit. With <commit>:<path> it prints a file exactly as it was in that commit.
Synopsis
git show [<options>] [<object>...]Options
Choosing the Right Option
show vs log vs diff
Three ways to look at history
| Command | Shows |
|---|---|
git log | A list of commits |
git show <commit> | One commit and its changes |
git diff A B | The difference between any two versions |
Examples
Last commit
git showShows HEAD with its diff.
Any commit
git show a1b2c3dShows that commit.
A file in an old commit
git show HEAD~2:app.jsPrints app.js as it was two commits ago.
Summary only
git show --statFiles changed instead of the full diff.
Workflow Examples
git log --onelineFind it
git show --stat a1b2c3dWhich files it touched
git show a1b2c3dThe full change
Troubleshooting
fatal: path 'x' does not exist in 'HEAD~1'
Cause: The file did not exist in that commit, or the path is wrong
Use the path from the repository root; check with git show --stat
A merge commit shows no diff
Cause: Merges show a combined diff only for conflicting lines
Use git show -m or git diff <merge>^1 <merge>
Tips & Pitfalls
Best Practices
- ✓Use --stat first on large commits.
- ✓Use commit:path to read an old version without changing your files.
Common Mistakes
- ✗Writing git show HEAD~1 app.js (a filter) when you meant HEAD~1:app.js (the file content).
- ✗Using a path relative to your folder without ./ in commit:path — paths are from the repository root.
FAQ
git show <commit>.
To read it: git show <commit>:<path>. To restore it: git restore --source=<commit> <path>.