Read and compare records

Lesson 6 of 25 · Git: records, branches, and collaboration

Continue in the same disposable repository. The last chapter created two commits: one with the guide and one with ignore rules. List the recent records:

git --no-pager log -n 10
git --no-pager log --oneline -n 10
git --no-pager log -p -n 1

The default log starts with the newest reachable commit and normally shows its identifier, author, date, and message. --oneline condenses each entry. -n 10 limits the number shown, and --no-pager avoids an interactive viewer. Without it, a pager may open; q normally exits. -p adds a patch, which explains changes relative to a parent rather than displaying the complete snapshot. Exact identifiers, dates, and formatting vary.

Add another recorded change so the difference is easy to trace:

printf 'Check the soil before watering.\n' >> guide.md
git diff
git add guide.md
git diff --cached
git commit -m "Add soil check"
git --no-pager diff HEAD^ HEAD -- guide.md

HEAD normally refers to the current checked-out commit; HEAD^ names its first parent. The last command compares those two snapshots for guide.md: the added soil-check line appears with +. -- separates revisions and options from the file path. A diff presents a comparison, not the storage format for the whole commit. Before staging, plain git diff compares the working file with the index; after staging, --cached compares the index with the current commit.

Next: Follow the links.