Inspecting Commits
git show displays a single commit: its details and the changes it made. To use it — and almost every other Git command — you need ways to name commits: hashes, branch names, HEAD, and relative references like HEAD~2.
git show
With no argument, git show describes the commit you're on:
git show
commit 8d99c4fbe68c42d6ab76dba6ef77e497a6980698 (HEAD -> main)
Author: Sam Rivera <sam@example.com>
Date: Mon Mar 2 09:42:00 2026 +0000
Add cheese to omelette
diff --git a/omelette.txt b/omelette.txt
index b4927c2..671eb8e 100644
--- a/omelette.txt
+++ b/omelette.txt
@@ -1 +1 @@
-Omelette: eggs, butter
+Omelette: eggs, butter, cheeseGive it any reference to see a different commit. --stat lists files instead of the full diff, and --oneline shortens the header:
git log --oneline
8d99c4f (HEAD -> main) Add cheese to omelette cfe25ef Add sugar to pancakes 90c0089 Add omelette recipe c4f5e47 Add pancake recipe
git show --stat --oneline HEAD~1
cfe25ef Add sugar to pancakes pancakes.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Naming commits
| Reference | Means |
|---|---|
a1b2c3d | A commit hash — any unique prefix of at least 4 characters |
main, feature/login | The latest commit on that branch |
HEAD | The commit you're on now |
HEAD~1 or HEAD~ | Its parent — one commit back |
HEAD~3 | Three commits back, following first parents |
HEAD^2 | The second parent of a merge commit |
v1.0 | A tag (lesson 39) |
main@{yesterday}, HEAD@{2} | Where a branch or HEAD pointed in the past (lesson 20) |
~ walks back along the line of history; ^ picks between parents, which only matters for merge commits. For ordinary commits HEAD^ and HEAD~ mean the same thing. These work everywhere: main~2, a1b2c3d~1 and so on.
git rev-parse turns any reference into its full hash — useful to check what a reference means:
git rev-parse --short HEAD~2
90c0089
^ is a special character — write HEAD~1 instead of HEAD^, or quote it as "HEAD^". Git Bash and PowerShell don't have this problem.A file at a past commit
reference:path shows a file exactly as it was in that commit, without changing anything in your working tree:
git show HEAD~3:pancakes.txt
Pancakes: flour, milk, eggs
To list which files existed in a commit, use git ls-tree:
git ls-tree --name-only HEAD~3
pancakes.txt
Ranges
Many commands accept a range of commits. A..B means "commits reachable from B but not from A" — in a straight line of history, the commits after A up to and including B:
git log --oneline HEAD~3..HEAD
8d99c4f (HEAD -> main) Add cheese to omelette cfe25ef Add sugar to pancakes 90c0089 Add omelette recipe
With branches this answers useful questions. main..feature lists the commits on feature that aren't on main yet — what a merge would bring in. And origin/main..main lists commits you haven't pushed (lesson 35).
git log --oneline main..brunch
7ab5594 (brunch) Add feta to shakshuka 1b53e7f Add shakshuka recipe
Describing a commit
A few more commands report on commits without changing anything:
| Command | Shows |
|---|---|
git show --name-status HEAD | Each file with A (added), M (modified) or D (deleted) |
git branch --contains a1b2c3d | Which branches include a commit |
git merge-base main brunch | The last commit two branches have in common |
git cat-file -p HEAD | The raw commit object (lesson 42) |
git branch --contains HEAD~1
brunch * main
Try it yourself
In a repository with a few commits, print the file you changed most recently as it was two commits ago, without checking anything out. Then list the commits between HEAD~3 and HEAD with their changed files.