Skip to content

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.

Terminal window
git log
commit 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 notes

Each 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.

The most commonly used flag:

Terminal window
git log --oneline
b7e9d03 (HEAD -> main) Add difficulty and gear notes to Summit Challenge
a3f8c12 Add initial tour notes

One line per commit: short hash and subject. Useful for getting a quick overview of recent history.

Terminal window
git log --oneline --graph

Adds 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 notes

A useful combination to keep in mind for later:

Terminal window
git log --oneline --graph --all

--all shows all branches, not just the current one.

Show only the last N commits:

Terminal window
git log -5 # last 5 commits
git log -1 # just the most recent commit
Terminal window
git log --author="Your Name"

Or partial match:

Terminal window
git log --author="Brandon"

Useful when reading history on a multi-contributor project.

Terminal window
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:

Terminal window
git log --since="2026-05-01" --until="2026-05-31"
Terminal window
git log --grep="navigation"

Finds all commits whose message contains the string “navigation”. Case-sensitive by default; add -i for case-insensitive:

Terminal window
git log --grep="navigation" -i
Terminal window
git log --stat

Adds 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(+)

To see the full diff of a specific commit:

Terminal window
git show b7e9d03

Or the most recent commit:

Terminal window
git show HEAD

git show outputs the commit metadata followed by the full diff — what every file looked like before and after.

Terminal window
git log -- pine-ridge.txt

Shows only commits that touched pine-ridge.txt. Add --follow to track renames across history:

Terminal window
git log --follow -- pine-ridge.txt

Many developers create a shortcut for the combination they use most. In your terminal (not for now, just to know it exists):

Terminal window
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.

  1. Make two more commits in your git-practice repo so you have at least four total. Use meaningful messages.

  2. Run git log and read the full output.

  3. Run git log --oneline and compare the density of information.

  4. Run git log --stat and observe the file change summaries.

  5. Pick one commit hash from git log --oneline and run git show <hash>. Read the full diff.

  6. Run git log -- pine-ridge.txt to see only commits that touched that file.

  • git log shows the full commit history, most recent first. Press q to exit.
  • --oneline: one line per commit — short hash and subject.
  • --graph: ASCII art showing branch topology. Use with --oneline --all for 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.