Recall the daily loop from lesson 2-3, edit then git add then git commit. The step that actually adds a new snapshot to the project's history is git commit.
Only commit writes to the history. Edits change the working directory, and add only fills the staging area, so neither one leaves a trace in .git.
That division is worth keeping straight before this unit, because everything about to be read back out of the history was put there by a commit and nothing else.
git log
You will read history far more often than you write it: to find when a bug crept in, to see what a teammate shipped overnight, to work out why a line exists at all. All of that starts with git log, which prints the history, newest commit first:
$ git log commit c7d8e9f2a91b4c3d5e6f7a8b9c0d1e2f3a4b5c6d Author: Ada Lovelace <ada@example.com> Date: Tue Mar 3 14:12:05 2026 -0800 Add photo of finished pancakes commit a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0 Author: Ada Lovelace <ada@example.com> Date: Tue Mar 3 13:40:11 2026 -0800 Add pancake recipe
There's the full 40-character hash from lesson 1-2, plus author, date, and message for each commit. For a quick scan, most people use the condensed form:
$ git log --oneline c7d8e9f Add photo of finished pancakes a1b2c3d Add pancake recipe
One line per commit: short hash and message. If the history is long, log opens in a scrolling viewer, press q to quit it (same q as less in the terminal course).
git show and HEAD
git log lists commits, git show zooms into one:
$ git show a1b2c3d
prints that commit's author, date, message, and the exact line changes it introduced.
Run git show with no hash and it shows the commit you are currently standing on. Git's name for "where you currently are" is HEAD. Right after a commit, HEAD is that newest commit. You will see the word HEAD constantly in Git's output from now on, it always means your current position in the history.
Filtering a long history
Real projects have thousands of commits, so nobody reads git log raw for long. These are the flags engineers actually reach for.
| Flag | What it gives you |
|---|---|
-n 5 | only the newest 5 commits |
--oneline | one condensed line per commit |
--author=ada | only commits whose author matches |
--graph --all | the commit graph as ASCII art, every branch at once |
--graph --all becomes genuinely valuable once branches exist in unit 5, since it is the fastest way to see the shape of a history rather than infer it from a list.
Flags combine freely, and git log --oneline -n 5 is a common reflex before starting the day's work. It answers what happened most recently in about a second, which is the point: a filter you can type from muscle memory gets used, and one you have to look up does not.
A recorded session
This session explores the history of the recipe-book repo, which now has two commits.
Each step below shows the command and the output it printed.
Step 1. Print the compact one-line-per-commit history.
~/recipe-book $ git log --oneline c7d8e9f Add photo of finished pancakes a1b2c3d Add pancake recipe
Step 2. Zoom into the older commit, a1b2c3d.
~/recipe-book $ git show a1b2c3d commit a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0 Author: Ada Lovelace <ada@example.com> Date: Tue Mar 3 13:40:11 2026 -0800 Add pancake recipe diff --git a/pancakes.txt b/pancakes.txt +Pancakes +- flour +- eggs +- milk
git log --oneline prints the short hash and the commit message, one commit per line.
The flag condenses each entry from the five-line default down to a single line, dropping the author and date. What remains is exactly what you need for scanning, an identifier you can pass to another command and a message that says what the commit did.
This is one of the most-typed commands in all of Git. It is fast to read, it fits a long stretch of history on one screen, and the short hashes it prints work anywhere a full hash would.
Right after making a commit, HEAD refers to the commit you are standing on, which is that brand-new commit.
HEAD is Git's name for your current position in the history. Committing moves you onto the newly created snapshot, so HEAD follows along and stays there until you deliberately move somewhere else, which unit 5 covers with branches and unit 9 with detached checkouts.
Two practical consequences follow. git show with no argument prints the commit at HEAD, and shorthand like HEAD~1 means the commit before it, which is how most of the undo commands in unit 4 name their target.
The command that lists the commits in your repository, newest first, is git log.
It prints the project's diary, with the full hash, author, date, and message for each commit. Adding --oneline compresses that to one line per commit for scanning.
The pairing to remember is that git log surveys while git show <hash> inspects. The log tells you which commit is interesting and gives you the hash, and show then prints that commit's actual line changes.