Skip to content

Viewing History with git log ​

You made your first commit. Then another. Then a few more. Now you have a pile of commits and you need to see what happened, when, and by whom. git log is the tool for that.

This guide covers everything a beginner needs to read their project's history.

What git log shows ​

Run git log in any repository that has commits:

bash
git log

Output:

commit a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0 (HEAD -> main)
Author: Jane Doe <jane@example.com>
Date:   Mon Nov 10 14:30:00 2026 -0500

    Add payment retry logic

commit 9b8c7d6e5f4a3b2c1d0e9f8a7b6c5d4e3f2a1b0c
Author: Jane Doe <jane@example.com>
Date:   Mon Nov 10 12:00:00 2026 -0500

    Initial commit: project scaffold

Each entry shows:

  • Full commit SHA. The unique 40-character hash identifying the commit.
  • Author. Who wrote it (configured via git config user.name and user.email).
  • Date. When the commit was created.
  • Message. The commit message. The first line is the subject. Blank line, then the body.

Newest commits appear first (reverse chronological order).

Compact view: --oneline ​

Full SHAs are verbose. For a quick scan:

bash
git log --oneline
a1b2c3d (HEAD -> main) Add payment retry logic
9b8c7d6 Initial commit: project scaffold

This shows the abbreviated SHA (7 characters) and the subject line. Use this 90% of the time.

See the branch structure: --graph and --all ​

When you have branches, git log --oneline --graph shows how they connect:

bash
git log --oneline --graph --all
* a1b2c3d (HEAD -> main) Add payment retry logic
| * f5e6d7c (feature/search) Add search index
| * e4f5a6b Refactor search results
|/
* 9b8c7d6 Initial commit: project scaffold

Each * is a commit. The lines show parent relationships. |/ means a branch was merged or diverged. --all shows commits on every branch, not just the current one.

Filtering what you see ​

By number of commits ​

bash
git log --oneline -5      # last 5 commits
git log --oneline -1      # just the most recent

By author ​

bash
git log --author="Jane"
git log --oneline --author="jane@example.com"

Matches any commit where the author name or email contains the string.

By date ​

bash
git log --oneline --since="2026-11-01"
git log --oneline --until="2026-11-10"
git log --oneline --after="2 weeks ago"

--since and --after are the same. --until and --before are the same. Accept "2026-11-01", "2 weeks ago", "yesterday", "2026-11-01T12:00:00".

By commit message ​

bash
git log --oneline --grep="retry"
git log --oneline --grep="fix|bug"  # regex: pipe means OR

Matches commits whose message (subject + body) contains the pattern.

By file ​

bash
git log --oneline -- src/payments/

Only shows commits that touched files in that directory or path.

Seeing what changed ​

Files changed ​

bash
git log --oneline --name-only

Adds a list of changed files after each commit:

a1b2c3d Add payment retry logic
src/payments/retry.go
src/payments/retry_test.go
src/config/defaults.go

Stats per commit ​

bash
git log --oneline --stat

Shows files changed, insertions, and deletions:

a1b2c3d Add payment retry logic
 src/payments/retry.go      | 45 ++++++++++++++++++++++++++
 src/payments/retry_test.go | 30 ++++++++++++++++
 src/config/defaults.go     |  2 ++
 3 files changed, 77 insertions(+)

The actual diff ​

bash
git log -p

Shows the full patch (diff) for each commit. Use this sparingly. It is a lot of output. Pipe it through less or add -1 to see just one commit:

bash
git log -p -1

What's happening here ​

CommandWhat Git doesWhat you see
git logWalks the commit graph from HEAD backwardFull commit details
git log --onelineSame walk, abbreviated outputOne line per commit
git log --graphRenders parent-child relationshipsASCII branch lines
git log --grep=Filters commits by message contentMatching commits only
git log -- <path>Filters commits touching a pathMatching commits only
git log -pGenerates diff for each commitPatch content
git log --allWalks every ref, not just current branchAll commits in repo

Git does not store diffs. Each commit is a full snapshot. When you run git log -p, Git computes the diff by comparing the commit's tree with its parent's tree. That is why asking for patches is slower than listing commits.

Common mistakes ​

MistakeWhat happensHow to fix
git log in a repo with no commitsNothing prints. No error.Make a commit first
Forgetting --oneline in a big repoTerminal fills with full SHAsq quits the pager. Add --oneline next time
git log --all when you meant just current branchShows extra commits from other branchesOmit --all to see only the current branch
git log --grep=fix matches nothingEmpty outputCheck spelling. Grep is case-sensitive by default; add -i for case-insensitive: --grep=fix -i
git log -- src/ includes subdirectory matchesCorrect behavior. File filtering is recursiveUse :(literal)src/ to match exactly or add a trailing slash
Piping git log -p without limitingMassive output, terminal scrollback lostAdd -5 or --since= to bound the range

Combining filters ​

Filters stack. This shows commits from the last 7 days by Jane touching payment files, with stats:

bash
git log --oneline --stat --since="7 days ago" --author="Jane" -- src/payments/

Order does not matter. All matching filters apply as an AND.

Quick reference ​

bash
git log                          # Full history
git log --oneline                # One line per commit
git log --oneline -10            # Last 10 commits, compact
git log --oneline --graph --all  # Branch topology
git log --author="Name"          # Filter by author
git log --since="2 weeks ago"    # Filter by date
git log --grep="fix"             # Filter by message
git log --oneline -- src/        # Filter by path
git log --stat                   # Show file change stats
git log -p                       # Show full diffs
git log --oneline --graph --all --decorate  # Everything, compact

Next steps ​

Try git log --oneline --graph --all in a repo with multiple branches. The ASCII graph is the quickest way to understand your repo's topology. When you need to find a specific commit, combine --grep, --author, and --since instead of scrolling through hundreds of entries.

Git Master — Git Reference for Every Skill Level