Viewing History
Once you have more than one commit, the real value of git starts to show: a complete, searchable record of exactly what changed, when, and why. This chapter covers the four commands you'll use to read that history — git log, git diff, git status, and git show — each answering a slightly different question about your project's past.
git log — The Story So Far
git log lists every commit in the current branch's history, most recent first. Each entry shows the commit hash, author, date, and message.
commit a1b2c3d4e5f6...
Author: Philip Osztromok <you@example.com>
Date: Fri Jun 19 14:02:11 2026
Fix login validation bug
commit f9e8d7c6b5a4...
Author: Philip Osztromok <you@example.com>
Date: Fri Jun 19 11:30:45 2026
Add initial homepage and stylesheet
Useful log variations
$ git log --oneline
a1b2c3d Fix login validation bug
f9e8d7c Add initial homepage and stylesheet
$ # Visual branch graph — essential once you start branching (Ch4)
$ git log --oneline --graph --all
$ # Only the last 5 commits
$ git log -5
$ # Only commits touching one specific file
$ git log -- index.html
git config --global alias.lg "log --oneline --graph --all" lets you just type git lg from then on.
git diff — What Actually Changed
git diff shows line-by-line changes. Used without arguments, it shows changes in your working directory that haven't been staged yet — exactly what would be added if you ran git add right now.
Red lines (prefixed -) were removed; green lines (prefixed +) were added. Lines with no prefix are unchanged context, shown so you can see where the change sits.
Diff variations that matter
$ git diff --staged
$ # Difference between two specific commits
$ git diff a1b2c3d f9e8d7c
$ # Difference for one specific file only
$ git diff index.html
git diff shows unstaged changes only. If you've already run git add, those changes disappear from plain git diff output — not because they vanished, but because they moved to the staging area. Use git diff --staged to see them there instead.
git status — Revisited
Chapter 2 introduced git status for checking what's staged. With history now in the picture, it also tells you how your branch relates to the last commit and to any remote (covered in Chapter 5):
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: index.html
git status and git diff work well together: status tells you which files changed, diff tells you exactly what changed inside them.
git show — Inspecting One Specific Commit
git show displays the full details of a single commit — message, metadata, and the complete diff of everything that commit changed, in one view.
commit a1b2c3d4e5f6...
Author: Philip Osztromok <you@example.com>
Date: Fri Jun 19 14:02:11 2026
Fix login validation bug
Useful git show variations
$ git show HEAD
$ # One commit before the most recent
$ git show HEAD~1
$ # Show only the file list changed, not the full diff
$ git show --stat HEAD
HEAD always refers to your current commit — usually the tip of whichever branch you're on. HEAD~1 means "one commit before that," HEAD~2 means two before, and so on. This shorthand works in almost any git command that expects a commit, and saves having to copy-paste hashes for recent history.
Command Reference
| Command | What it does |
|---|---|
| git log | Full commit history, most recent first |
| git log --oneline | Compact one-line-per-commit view |
| git log --graph --all | Visual branch graph across all branches |
| git diff | Unstaged changes in the working directory |
| git diff --staged | Changes already staged, not yet committed |
| git status | What's staged, unstaged, or untracked right now |
| git show <commit> | Full details and diff for one specific commit |
| HEAD / HEAD~1 / HEAD~2 | Shorthand for "current commit" and N commits before it |
Chapter 3 Quick Reference
- git log — full history; git log --oneline for the compact view you'll use daily
- git diff — unstaged changes only; git diff --staged for what's already staged
- git status — quick check of what's changed before deciding what to stage/commit
- git show <commit> — full message + diff for one specific commit
- HEAD — your current commit; HEAD~1, HEAD~2 — N commits back from there
- Good habit: run status → diff → log in that order when you're not sure what state a project is in
- Next chapter: branching — creating, switching, and merging, and what a branch actually is under the hood