You have learned to browse history with git log. But browsing gives you the highlights, the commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed. message, the author, the date. Sometimes you need the full story. You need to see exactly what changed in a specific commit: which files were modified, which lines were added or removed.
This is where git show comes in. It is like picking up a specific chapter from a book and reading it in detail, rather than skimming the table of contents.
The git show command
At its simplest, git show displays the most recent commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed.:
git showThis outputs the commit metadata (hash, author, date, message) plus the full diffWhat is diff?A comparison showing exactly which lines were added, removed, or changed between two versions of code. of every file changed. It gives you the complete picture for one commit.
Referencing specific commits
You rarely want to see just the latest commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed.. Usually you are investigating a specific change from the past.
By commit hash
# Full hash (40 characters)
git show a1b2c3d4e5f6789012345678901234567890abcd
# Short hash (7-8 characters) - usually enough
git show a1b2c3dabc123). When you copy AI-generated git commands, always replace placeholder hashes with real ones from your own git log --oneline output. A wrong hash gives you a confusing "bad object" error.Relative references
Instead of memorizing hashes, you can reference commits relative to where you are now:
| Reference | Meaning |
|---|---|
HEAD | The current commit (latest) |
HEAD~1 or HEAD^ | One commit before HEAD |
HEAD~2 | Two commits before HEAD |
HEAD~3 | Three commits before HEAD |
HEAD~10 | Ten commits before HEAD |
# What did I just commit?
git show HEAD
# What was in the commit before that?
git show HEAD~1
# What changed three commits ago?
git show HEAD~3Combining with log
Find a commit with log, then inspect it:
# Find commits mentioning "bug"
git log --oneline --grep="bug"
# a1b2c3d Fix critical login bug
# e4f5g6h Fix navigation bug on mobile
# Inspect the first one
git show a1b2c3dCustomizing the output
Show statistics only
git show --stat a1b2c3dShows what files changed and by how much, but not the actual line changes:
src/auth.js | 12 +++++++----
src/login.html | 5 +++--
2 files changed, 10 insertions(+), 7 deletions(-)Show only the commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed. message
git show --quiet a1b2c3dMetadata and message only, no diffWhat is diff?A comparison showing exactly which lines were added, removed, or changed between two versions of code. at all.
Show a specific file at a commit
git show a1b2c3d:src/auth.jsThis outputs the entire content of src/auth.js as it existed in that commit. It is like time travel for your code.
Viewing file history with git blame
Sometimes you care about a specific line in a specific file. Who wrote it? When? Why?
git blame src/auth.jsOutput:
a1b2c3d4 (Sarah Chen 2024-01-15 1) import jwt from 'jsonwebtoken';
a1b2c3d4 (Sarah Chen 2024-01-15 2)
e4f5g6h7 (Mike Ross 2024-01-14 3) export function loginUser(credentials) {Each line shows: commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed. hash, author, date, line number, and the actual content.
Blame specific lines
# Show only lines 10 through 20
git blame -L 10,20 src/auth.jsFound a suspicious line? See the full commit:
git show e4f5g6h7Seeing file evolution
Want the entire history of changes to a specific file?
git log -p -- src/auth.jsThe -p flag (patch) shows the full diffWhat is diff?A comparison showing exactly which lines were added, removed, or changed between two versions of code. for each commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed.. Combined with the file path, you see every change ever made to that file.
Quick reference
| Command | What it shows |
|---|---|
git show | Latest commit details + diff |
git show abc123 | Specific commit |
git show HEAD~1 | Previous commit |
git show --stat | Statistics only |
git show --quiet | Metadata only, no diff |
git show abc:file.js | File as it was at that commit |
git blame file.js | Who changed each line |
git blame -L 10,20 file.js | Blame specific lines |
git log -p -- file.js | All changes to a file |