git log — Reading History
Every commit you have ever made lives in your repository’s history, readable at any time. git log is the tool for reading that history. On a small practice repo, the default output is fine. On a real project with hundreds of commits, you need the right flags to surface what you are looking for.
The default output
Section titled “The default output”git logcommit b7e9d03a2f1c... (HEAD -> main)Author: Your Name <you@example.com>Date: Thu May 28 10:15:00 2026 -0700
Add difficulty and gear notes to Summit Challenge
commit a3f8c12d4e9f...Author: Your Name <you@example.com>Date: Wed May 27 09:00:00 2026 -0700
Add initial tour notesEach commit entry shows the full hash, author, date, and message. The most recent commit is at the top. Press q to exit the log pager when you are done reading.
—oneline: compact history
Section titled “—oneline: compact history”The most commonly used flag:
git log --onelineb7e9d03 (HEAD -> main) Add difficulty and gear notes to Summit Challengea3f8c12 Add initial tour notesOne line per commit: short hash and subject. Useful for getting a quick overview of recent history.
—graph: branch topology
Section titled “—graph: branch topology”git log --oneline --graphAdds ASCII art showing branch and merge structure. Becomes more useful once you start working with branches in Module 03. On a linear history, it just adds a * before each commit:
* b7e9d03 (HEAD -> main) Add difficulty and gear notes to Summit Challenge* a3f8c12 Add initial tour notesA useful combination to keep in mind for later:
git log --oneline --graph --all--all shows all branches, not just the current one.
-n: limiting output
Section titled “-n: limiting output”Show only the last N commits:
git log -5 # last 5 commitsgit log -1 # just the most recent commitFiltering by author
Section titled “Filtering by author”git log --author="Your Name"Or partial match:
git log --author="Brandon"Useful when reading history on a multi-contributor project.
Filtering by date
Section titled “Filtering by date”git log --since="2026-01-01"git log --until="2026-06-01"git log --since="2 weeks ago"git log --since="yesterday"Combine them to search a date range:
git log --since="2026-05-01" --until="2026-05-31"Searching commit messages
Section titled “Searching commit messages”git log --grep="navigation"Finds all commits whose message contains the string “navigation”. Case-sensitive by default; add -i for case-insensitive:
git log --grep="navigation" -iSeeing what files changed in each commit
Section titled “Seeing what files changed in each commit”git log --statAdds a summary of which files changed and how many lines were added or removed in each commit:
commit b7e9d03 (HEAD -> main)Author: Your Name <you@example.com>Date: Thu May 28 10:15:00 2026 -0700
Add difficulty and gear notes to Summit Challenge
summit-challenge.txt | 4 ++++ 1 file changed, 4 insertions(+)Viewing a single commit
Section titled “Viewing a single commit”To see the full diff of a specific commit:
git show b7e9d03Or the most recent commit:
git show HEADgit show outputs the commit metadata followed by the full diff — what every file looked like before and after.
Tracking history for a specific file
Section titled “Tracking history for a specific file”git log -- pine-ridge.txtShows only commits that touched pine-ridge.txt. Add --follow to track renames across history:
git log --follow -- pine-ridge.txtA practical alias to consider
Section titled “A practical alias to consider”Many developers create a shortcut for the combination they use most. In your terminal (not for now, just to know it exists):
git log --oneline --graph --all --decorate--decorate adds branch and tag names to the output. As a one-liner, this gives a clean picture of the entire repo’s branch topology.
Exercise
Section titled “Exercise”-
Make two more commits in your
git-practicerepo so you have at least four total. Use meaningful messages. -
Run
git logand read the full output. -
Run
git log --onelineand compare the density of information. -
Run
git log --statand observe the file change summaries. -
Pick one commit hash from
git log --onelineand rungit show <hash>. Read the full diff. -
Run
git log -- pine-ridge.txtto see only commits that touched that file.
git logshows the full commit history, most recent first. Pressqto exit.--oneline: one line per commit — short hash and subject.--graph: ASCII art showing branch topology. Use with--oneline --allfor the full picture.-n: limit to the last N commits.--author,--since,--until,--grep: filter the log by author, date, or message content.--stat: add a file-change summary to each commit.git show <hash>: see the full diff of a specific commit.git log -- <file>: filter history to commits that touched a specific file.
Module 02 is complete. Module 03 introduces branches — one of Git’s most powerful features — and explains how to create parallel lines of development, switch between them, and merge changes back together.