Viewing History

Course 1 · Ch 3
Viewing History — log, diff, status, show
Reading the story your commits already tell — and learning to actually trust what git is showing you

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.

$ git log
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
a1b2c3d
Fix login validation bug
Most recent — HEAD points here
f9e8d7c
Add initial homepage and stylesheet
Root commit — the very first snapshot

Useful log variations

$ # Compact one-line-per-commit view — the one you'll use most
$ 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 log --oneline --graph --all is worth aliasing
Most experienced git users set up a shortcut for this exact combination early on — it's the single most useful view once branches enter the picture. 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.

$ git diff
diff --git a/index.html b/index.html
@@ -12,7 +12,7 @@
<body>
- <h1>Welcome</h1>
+ <h1>Welcome to my site</h1>
</body>

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

$ # Changes already staged, not yet committed
$ git diff --staged

$ # Difference between two specific commits
$ git diff a1b2c3d f9e8d7c

$ # Difference for one specific file only
$ git diff index.html
Plain git diff vs git diff --staged trips up almost everyone at first
Plain 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):

$ git status
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.

$ git show a1b2c3d
commit a1b2c3d4e5f6...
Author: Philip Osztromok <you@example.com>
Date: Fri Jun 19 14:02:11 2026

Fix login validation bug
diff --git a/login.js b/login.js
@@ -8,6 +8,6 @@
- if (password.length > 6) {
+ if (password.length >= 8) {

Useful git show variations

$ # The most recent commit, without typing its hash
$ 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 is just a pointer to "where you are right now"
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

CommandWhat it does
git logFull commit history, most recent first
git log --onelineCompact one-line-per-commit view
git log --graph --allVisual branch graph across all branches
git diffUnstaged changes in the working directory
git diff --stagedChanges already staged, not yet committed
git statusWhat's staged, unstaged, or untracked right now
git show <commit>Full details and diff for one specific commit
HEAD / HEAD~1 / HEAD~2Shorthand 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