Skip to content

git log

Exploring commit history with git log — viewing, filtering, and formatting past commits.

What you'll learn

  • How to view the commit history with git log
  • Useful flags: --oneline, --graph, --stat
  • Filtering by author, date, or number of commits
  • Viewing the details of a single commit with git show

Concept

What git log Does

git log shows the commit history of your repository — every commit in reverse chronological order, with its hash, author, date, and message.

git log

The default output is detailed:

commit a1b2c3d4e5f6... (HEAD -> main)
Author: Ada Lovelace <[email protected]>
Date:   Mon Jan 15 10:30:00 2025 +0000

    Add user login page with OAuth

commit f6e5d4c3b2a1...
Author: Alan Turing <[email protected]>
Date:   Sun Jan 14 16:45:00 2025 +0000

    Fix crash when cart is empty

Press q to exit the log viewer (it uses a pager like less).

The One-Line Format

The most useful flag is --oneline, which condenses each commit to a single line:

git log --oneline
a1b2c3d Add user login page with OAuth
f6e5d4c Fix crash when cart is empty
d4c3b2a Initial commit

This is the format most developers use day-to-day.

The Graph View

To see branches and merges visually:

git log --oneline --graph --all
* a1b2c3d (HEAD -> main) Add user login page
| * b2c3d4e (feature) Add dark mode
|/
* f6e5d4c Fix crash when cart is empty
* d4c3b2a Initial commit

This shows you how branches diverge and merge — essential for understanding your project's history.

Useful Flags

git log --oneline              # compact one-line format
git log --graph --oneline      # add branch graph
git log --stat                 # show files changed in each commit
git log -5                     # only the last 5 commits
git log --author="Ada"         # only commits by a specific author
git log --since="2 weeks ago"  # only recent commits
git log --grep="fix"           # commits with "fix" in the message
git log --follow README.md     # history of a specific file (including renames)

Viewing a Single Commit

To see the full details of one commit — what files changed and how — use git show:

git show a1b2c3d

This shows the commit metadata plus the full diff (the actual changes made in that commit).

Comparing Commits

git diff a1b2c3d f6e5d4c  # changes between two commits
git diff HEAD~1 HEAD       # changes in the last commit

Understanding git log and git diff together lets you navigate your project's entire history and understand exactly what changed, when, and why.

Example

              # View the full history (press q to exit)
git log

# Compact one-line view — the most useful format
git log --oneline

# See the last 5 commits only
git log --oneline -5

# Visual graph with all branches
git log --oneline --graph --all

# Show files changed in each commit
git log --stat -3

# Filter by author
git log --author="Ada" --oneline

# Filter by date
git log --since="2 weeks ago" --oneline

# Search commit messages
git log --grep="fix" --oneline

# View the details of a specific commit
git show HEAD  # the most recent commit
git show HEAD~1  # the commit before that

# See the history of a single file
git log --oneline --follow README.md

# Compare two commits
git diff HEAD~2 HEAD --stat
            

Covers the essential git log variations: compact, graph, filtered by author/date/message, and viewing a single commit with git show. The --oneline and --graph flags are the ones you will use most.

Try it

  • Code Diff

    Compare two versions — git log and git diff work together to show history.

  • CI/CD YAML Generator

    CI pipelines often display git log output — generate one to see.

Common mistakes

The mistake

Being stuck in the git log pager and not knowing how to exit

The fix

git log uses a pager (less). Press q to quit, space to page down, b to page up. Use git log --oneline for a quick view that often fits on one screen, or git log -n to limit output.

The mistake

Not knowing about --oneline and --graph flags

The fix

The default git log output is verbose. git log --oneline gives a compact view, and --graph --oneline --all shows branches visually. These two formats cover 90% of daily usage.

Related Snippets

Related Cheatsheets

Practice git log

2 exercises

Practice git log

Look up unfamiliar terms

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

View glossary

Build real projects

Apply what you learned by building guided projects with starter code and solutions.

View projects

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors