Inspecting Objects (git show)
git show is the “tell me everything about this thing” command. Pass it a commit hash, a branch name, a tag, or even a file at a specific point in history, and it prints the relevant information in a readable form. It is the natural companion to git log — once you find an interesting commit in the log, git show opens it up.
Showing a commit
git show 1f9ab2c # or git show HEAD # the current commit git show HEAD~3 # three commits back git show main # the tip of main
What you see
commit 1f9ab2c0e8b4a7d2f0c... (HEAD -> main)
Author: Your Name <you@example.com>
Date: Mon Jan 1 10:00:00 2025 +0000
Add login form validation
diff --git a/src/login.js b/src/login.js
index 1a2b3c4..5d6e7f8 100644
--- a/src/login.js
+++ b/src/login.js
@@ -10,7 +10,9 @@ function submit(form) {
...
+ if (!form.email) return error("Email required");
+ if (form.password.length < 8) return error("Password too short");
...That is the commit metadata plus the diff of every file the commit changed.
Useful flags
--stat— show a per-file change summary instead of the full diff.--name-only— just the file names.--name-status— file names + A/M/D/R.-w— ignore whitespace.--no-patch— show only the metadata, no diff.-p— show the patch (the default).
Showing a specific file at a specific commit
What did this file look like back then?
git show 1f9ab2c:src/app.js # Prints the entire contents of src/app.js as it was in that commit git show HEAD~5:README.md > old-readme.md # Save it to a file for comparison
Showing a tag
# Annotated tag — shows the tag, its message, and the commit git show v1.0 # Lightweight tag — shows just the commit it points to git show release-2024-01-01
Showing a tree (directory listing of a commit)
git show --stat HEAD # which files changed git show --raw HEAD # raw object info git ls-tree -r HEAD # full file listing at HEAD
Showing a branch tip without the diff
git show main --no-patch # commit ... # Author: ... # Date: ... # # (message)
Showing what a merge actually merged
Merge commits have two parents. By default git show of a merge commit shows a combined diff. To see each parent separately:
git show -m <merge-commit> # shows merge as separate diffs git show --first-parent <merge-commit> git log -m -p <merge-commit>
git show vs git log -1 vs git diff
git show <commit>— full content of one commit (metadata + diff).git log -1 <commit>— same but goes through the log formatting machinery; lets you use--pretty.git diff <a> <b>— only the diff between two arbitrary references.
Practical examples
What changed in the merge commit?
git log --merges --oneline -5 # find a merge git show abc1234 --stat
Recover an old version of a file
git log --oneline -- path/to/file.js # find the version git show 1f9ab2c:path/to/file.js > path/to/file.js git add path/to/file.js git commit -m "Restore old version of file.js"
Read a commit message only
git show --no-patch --pretty=fuller HEAD
git show to see the full story.