Git Log: The Complete Guide for 2026
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.
Table of Contents
- Quick start: 5 useful git log commands
- Commit ranges: main..feature and other patterns
- Filtering by author, date, and message
- Searching history: --grep vs -S vs -G
- Seeing what changed: -p, --stat, --name-status
- File history: paths, renames, and line history
- Formatting output: --oneline, --graph, --pretty
- Useful aliases for daily work
- Troubleshooting and best practices
- 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.”
| Range | Meaning | Example |
|---|---|---|
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
--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:
--all-matchmakes multiple--greppatterns behave like AND.--invert-grepexcludes matches.--regexp-ignore-casemakes grep case-insensitive.
4. Searching history: --grep vs -S vs -G
These three options are easy to mix up. Here’s the practical difference:
--grepsearches commit messages-Ssearches for commits where the number of occurrences changed (pickaxe)-Gsearches the diff text using a regex
# 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
--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:
%hshort hash,%Hfull hash%ssubject (first line of message)%anauthor name,%aeauthor email%adauthor date (controlled by--date=)%ddecorations (branch/tag names)
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
- Pager confusion: Press
qto quit. To disable the pager for a command:git --no-pager log ... - Slow logs in huge repos: Add
-n 200, narrow with--since, or limit to a path:git log -- src/ - Merges make it unreadable: Try
--no-mergesor--first-parent - Need the details for one commit: Use git show (covered in our Git complete guide)
- Need to find a regression: Use git bisect to binary-search history
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.