Git Log: The Complete Guide for 2026

Published February 15, 2026 · 20 min read

git log is the fastest way to answer questions like: What changed? When did it change? Who changed it? and Which branch has that commit? If you can describe what you’re looking for (a file, a string, an author, a time window), git log can usually find it.

This guide focuses on practical workflows: a good default log view, comparing branches, filtering by time/author, searching commits, following file history (including renames), and building a few aliases you’ll use every day.

⚙ Quick reference: Bookmark the Git Commands Cheat Sheet for a one-page list of essential commands and flags.

Table of Contents

  1. Quick start: 5 useful git log commands
  2. Commit ranges: main..feature and other patterns
  3. Filtering by author, date, and message
  4. Searching history: --grep vs -S vs -G
  5. Seeing what changed: -p, --stat, --name-status
  6. File history: paths, renames, and line history
  7. Formatting output: --oneline, --graph, --pretty
  8. Useful aliases for daily work
  9. Troubleshooting and best practices
  10. FAQ

1. Quick start: 5 useful git log commands

If you only remember a handful of commands, make them these:

# A readable graph (great default)
git log --oneline --decorate --graph --all

# Show what changed in the last commit
git log -1 -p

# File-level summary per commit
git log --stat

# History for a file or folder
git log -- path/to/file-or-folder

# Find commits where a string was added/removed
git log -S "function authenticate" -- path/to/file

Tip: if git log opens in a pager (usually less), press q to quit. Use / to search, n for next match, and G to jump to the end.

2. Commit ranges: main..feature and other patterns

Ranges are the difference between “show me everything” and “show me exactly what I need.”

RangeMeaningExample
A..B Commits reachable from B but not A git log main..feature
A...B Commits on either side that aren’t shared (symmetric difference) git log --left-right main...feature
HEAD~10..HEAD The last 10 commits on the current branch git log --oneline HEAD~10..HEAD

Common “what’s in my branch?” workflow:

# Commits on feature that are not on main
git log --oneline main..feature

# Compare both sides (left=main, right=feature)
git log --oneline --left-right main...feature
Tip: If merges make your history noisy, try --no-merges or --first-parent to focus on the mainline.

3. Filtering by author, date, and message

Filters are composable. Start broad, then tighten until the output is small and clear.

# By author name or email (substring match)
git log --author="Alice"

# By time window
git log --since="2026-02-01" --until="2026-02-15"
git log --since="2 weeks ago"

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

# Combine filters
git log --since="1 month ago" --author="Alice" --grep="fix" --oneline

If you need more powerful message search behavior:

These three options are easy to mix up. Here’s the practical difference:

# Message search ("who wrote a commit mentioning X?")
git log --grep="rate limit" --oneline

# Pickaxe search ("when was this token introduced/removed?")
git log -S "MAX_RETRIES" --oneline

# Regex diff search ("when did code matching this pattern change?")
git log -G "def\\s+authenticate" --oneline

When searching content, limit the scope with a path. It’s faster and produces fewer false positives:

git log -S "MAX_RETRIES" -- src/
git log -G "authenticate" -- app/auth.py

5. Seeing what changed: -p, --stat, --name-status

Sometimes the commit list is not enough — you want to see what actually changed.

# Show patch/diff for each commit
git log -p

# Summary of files changed + line counts
git log --stat

# Just file names (or file status)
git log --name-only
git log --name-status

Useful combinations:

# Compact view: commit + files changed
git log --oneline --name-status -10

# Only commits that touched a path
git log --oneline -- src/auth/

# Only commits that added or modified files
git log --name-status --diff-filter=AM --oneline

6. File history: paths, renames, and line history

To see history for a specific file or folder, add -- and then the path:

git log --oneline -- path/to/file
git log --stat -- path/to/folder/

To follow a file across renames, use --follow:

git log --follow --oneline -- path/to/file
Note: --follow works best for a single file. If you provide multiple paths, Git may ignore follow/rename detection.

If you need to track changes to a specific function or range of lines, try -L:

# Track the history of a function (language-dependent heuristics)
git log -L :functionName:path/to/file

7. Formatting output: --oneline, --graph, --pretty

Most developers end up with a “favorite” log format. Start here:

git log --graph --oneline --decorate --all

When you need more control, use --pretty=format: with placeholders:

git log --graph --decorate --date=short \
  --pretty=format:'%C(auto)%h%d %s %C(black)%C(bold)%cr %C(reset)%C(blue)%an%C(reset)'

This prints a colorful one-line view with relative time (%cr) and author, while keeping the commit subject readable.

8. Useful aliases for daily work

You can make your favorite views memorable with Git aliases. Example:

# Set aliases (global)
git config --global alias.lg "log --graph --oneline --decorate"
git config --global alias.lga "log --graph --oneline --decorate --all"
git config --global alias.last "log -1 -p"

# Use them
git lg
git lga
git last

Or add them to ~/.gitconfig:

[alias]
  lg = log --graph --oneline --decorate
  lga = log --graph --oneline --decorate --all
  last = log -1 -p
  who = shortlog -sn --all

9. Troubleshooting and best practices

If you’re cleaning up history, combine log with safe undo tools like git revert and git reflog.

FAQ

Why does git log show different results from GitHub’s web UI?

GitHub often defaults to the currently selected branch, while your local repo might be on another branch, behind the remote, or missing refs. Run git fetch --all --prune, confirm your branch, and use explicit ranges like git log origin/main..HEAD to be unambiguous.

How do I see only commits that touched a specific file?

Use path limiting: git log -- path/to/file. Add --follow to track renames for that file.

How do I export commits as patches?

Use git format-patch. For example: git format-patch main..feature will create one patch file per commit that exists in feature but not main.

Related Resources

Git: The Complete Guide
Everything from branching to recovery and workflows
Git Diff Complete Guide
Review changes across staged/unstaged, commits, and branches
Git Blame Complete Guide
Track who changed a line (ranges, renames, moved code, ignore-revs)
Git Undo (Reset vs Revert)
Safely undo changes locally or on shared branches
Git Bisect Guide
Find the exact commit that introduced a bug
Git Rebase Complete Guide
Rewrite history cleanly with interactive rebase
Git Commands Cheat Sheet
One-page quick reference for daily Git workflows
Diff Checker Tool
Compare text changes side-by-side (patches, config, docs)