Git Log and Show: Read Commit History
Read history without changing files
git log lists commits reachable from a starting revision (HEAD by default). git show inspects an object; for a typical commit it displays metadata and the patch against its parent. Use them to answer what changed and when, without checking out an old version.
Prepare a tiny history
Use Bash or Git Bash and Git 2.47.3 (tested baseline). Choose a fresh directory outside any existing repository; stop if setup fails. The dates and names are fictional. The long date assignments only make the later date-filter example repeatable; they apply to one command. Run the setup once for this chapter.
mkdir bytemind-history-lab && cd bytemind-history-labgit init -b maingit config --local user.name "ByteMind Learner"git config --local user.email learner@example.invalidprintf 'Tea\nRice\n' > notes.txtgit add -- notes.txtGIT_AUTHOR_DATE=2025-01-01T12:00:00Z GIT_COMMITTER_DATE=2025-01-01T12:00:00Z git -c commit.gpgsign=false commit -m "Add notes"printf 'Tea\nMilk\n' > notes.txtgit add -- notes.txtGIT_AUTHOR_DATE=2025-01-02T12:00:00Z GIT_COMMITTER_DATE=2025-01-02T12:00:00Z git -c commit.gpgsign=false commit -m "Replace rice with milk"printf 'Shopping project\n' > README.mdgit add -- README.mdGIT_AUTHOR_DATE=2025-01-03T12:00:00Z GIT_COMMITTER_DATE=2025-01-03T12:00:00Z git -c user.name="Lab Reviewer" -c commit.gpgsign=false commit -m "Add project readme"Three commits now exist on main: Add notes, Replace rice with milk, Add project readme. Hashes may differ on your system.
Find and inspect a commit
Use a compact list to find a commit, then inspect it. -n 2 limits the list to two commits. HEAD~1 means follow the first parent once from HEAD; here it identifies the second commit.
The list shows abbreviated IDs and the subjects Add project readme and Replace rice with milk. The stat reports notes.txt; the final command prints Tea and Milk on separate lines. An abbreviated ID must uniquely identify an object; copy a real ID from your log, not an illustrative hash.
See the graph and its labels
A commit stores parent IDs, so history is a graph, not a row number. In this linear lab the newest commit has one parent, and the first has none. Branch labels indicate named references; later chapters teach branching. HEAD can also point directly to a commit (detached HEAD).
The three commits appear connected, with main and HEAD at the newest one. In larger histories --all can include commits reachable from other refs; it does not mean every object on disk. If a pager opens, press q to leave it.
Practice and common mistakes
Find the commit that changed Rice to Milk. Inspect its message and file contents, then run git status --short to confirm nothing changed. Do not confuse an author date with a guaranteed chronological order in a branched history, or assume log includes unsaved work.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Git Log and Show: Read Commit History — knowledge check
Interpret Git history and differences using the chapter fixture.
Which command lists abbreviated commit IDs and subjects?
In the three-commit linear lab, what does HEAD~1 identify?
Which command prints notes.txt as stored in the second commit?
Why might a copied short ID stop identifying a unique object?
What does a clean status after inspecting history establish?