git show — Inspecting Commits
git show displays the details of a specific commit — its message, author, and the exact changes (diff) it introduced. While git log gives you the overview, git show gives you the full picture of a single commit.
Basic Usage
git show
With no arguments, it shows the most recent commit (HEAD). The output includes:
commit a1b2c3d4e5f6...
Author: Alice <[email protected]>
Date: Mon Jan 15 10:30:00 2024
Add user authentication
diff --git a/auth.js b/auth.js
new file mode 100644
--- /dev/null
+++ b/auth.js
@@ -0,0 +1,5 @@
+function authenticate(user) {
+ // verify credentials
+ return true;
+}
Showing a Specific Commit
git show e4f5g6h
git show main
git show v1.0
You can pass any ref — a SHA, branch name, or tag.
Reading the Output
The output has two parts:
1. Commit Metadata
- Commit SHA — the full hash
- Author — name and email
- Date — when it was created
- Message — the commit message (indented)
2. Diff
Shows exactly what changed:
- Lines starting with
+were added - Lines starting with
-were removed @@headers show the line numbers affected
Useful Variations
| Command | Shows |
|---|---|
git show HEAD | Latest commit |
git show HEAD~1 | Previous commit |
git show <sha> | Specific commit |
git show <branch> | Latest commit on a branch |
git show <tag> | Tagged commit |
git show vs git log vs git diff
| Command | Purpose |
|---|---|
git log | List multiple commits (overview) |
git show <commit> | One commit's metadata + diff |
git diff A B | Differences between two points |
Try it!
- View the latest commit in detail:
git show - View the log to find an older commit:
git log --oneline - Show a specific commit:
git show <sha>(use a SHA from the log) - Compare:
git show HEAD~1to see the previous commit
Key Points
git showdisplays a commit's full details and diff- With no arguments, it shows HEAD
- Accepts any ref: SHA, branch, tag, HEAD~N
- The diff shows exactly what that single commit changed
- Great companion to
git blame— blame finds the SHA, show explains it