Git/
Lesson

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 show

This 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.

02

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 a1b2c3d
AI pitfall
AI tools sometimes generate fake commit hashes in their examples (like abc123). 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:

ReferenceMeaning
HEADThe current commit (latest)
HEAD~1 or HEAD^One commit before HEAD
HEAD~2Two commits before HEAD
HEAD~3Three commits before HEAD
HEAD~10Ten 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~3

Combining 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 a1b2c3d
03

Customizing the output

Show statistics only

git show --stat a1b2c3d

Shows 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 a1b2c3d

Metadata 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.js

This outputs the entire content of src/auth.js as it existed in that commit. It is like time travel for your code.

04

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.js

Output:

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.js

Found a suspicious line? See the full commit:

git show e4f5g6h7
05

Seeing file evolution

Want the entire history of changes to a specific file?

git log -p -- src/auth.js

The -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.

06

Quick reference

CommandWhat it shows
git showLatest commit details + diff
git show abc123Specific commit
git show HEAD~1Previous commit
git show --statStatistics only
git show --quietMetadata only, no diff
git show abc:file.jsFile as it was at that commit
git blame file.jsWho changed each line
git blame -L 10,20 file.jsBlame specific lines
git log -p -- file.jsAll changes to a file