Appearance
Advanced git log: Filtering, Formatting, and Visualization
You know git log and git log --oneline. That covers the basics. But git log has a dozen filtering flags and a custom format system that turns it into a query tool for your project's history. This guide covers the patterns a daily developer actually reaches for.
Filtering by time
bash
# Commits from the last 2 weeks
git log --since="2 weeks ago"
# Commits between two dates
git log --after="2025-01-01" --before="2025-06-01"
# Commits since a specific time
git log --since="yesterday"
git log --since="2025-03-15T09:00:00"The --since/--after and --until/--before flags accept any date format Git's date parser understands. Use them to answer "what changed in this sprint?" or "who deployed on Friday night?"
Filtering by author
bash
# All commits by one person
git log --author="Jane"
# Multiple authors (OR)
git log --author="Jane\|Bob"
# Exclude a bot
git log --perl-regexp --author="^(?!bot-name)"The --author flag is a regex, not an exact match. --author="Jane" matches "Jane Doe" and "Jane Smith". Use --perl-regexp for negative lookaheads if you need to exclude authors.
Filtering by content
bash
# Commits that touched a specific function name
git log -S"retryPayment" --oneline
# Commits where a regex matches the diff
git log -G"TODO\|FIXME" --oneline
# Commits that changed a specific file
git log --oneline -- src/payments/api.ts
# Commits that changed any file in a directory
git log --oneline -- src/payments/-S (pickaxe) finds commits that changed the number of occurrences of a string. It catches additions, deletions, and modifications. -G finds commits where a regex matches any added or removed line. They answer different questions:
-Sis for tracking a specific identifier across history-Gis for finding pattern changes (did anyone add a new TODO?)
Filtering by commit message
bash
# Commits whose message contains "wip" (case-insensitive)
git log --grep="wip" -i
# Commits whose message matches a regex
git log --grep="fix(.*):"
# Combine with author filter (AND)
git log --grep="hotfix" --author="Jane"Merges and topology
bash
# Show only merge commits
git log --merges
# Show only non-merge commits
git log --no-merges
# Show only commits on the first-parent chain
git log --first-parent
# Show all branches, not just the current one
git log --all--first-parent is the most useful of these. When you merge a feature branch into main, the merge commit has two parents. --first-parent follows only the mainline, skipping every commit that happened on the merged branch. This gives you the "high-level" history of your project.
Custom output format
The --format flag lets you print exactly what you need:
bash
git log --format="%h %s (%an, %ar)"Common placeholders:
| Placeholder | Output |
|---|---|
%h | Abbreviated commit hash |
%H | Full commit hash |
%s | Subject (first line of message) |
%b | Body (rest of message) |
%an | Author name |
%ae | Author email |
%ad | Author date (respects --date=) |
%ar | Author date, relative ("2 days ago") |
%cn | Committer name (different from author after rebase) |
%D | Ref names (branches, tags pointing to this commit) |
Full format:
bash
git log --format="%h %s%n Author: %an <%ae>%n Date: %ar%n"This gives you a compact but readable entry:
a1b2c3d Fix payment retry on timeout
Author: Jane Doe <jane@example.com>
Date: 2 days agoGraph visualization
bash
git log --graph --oneline --allThe --graph flag draws ASCII lines showing branch and merge topology. Combine with --all to see every branch. This is the closest thing to a GUI graph in the terminal.
For a dense view:
bash
git log --graph --pretty=format:"%h %d %s" --allCombining filters
Most flags compose as AND filters. This finds every merge commit from Jane in the last month that touched the payments module:
bash
git log --merges --author="Jane" --since="1 month" --oneline -- src/payments/When not to use git log
| Situation | Use instead |
|---|---|
| Need machine-readable output (CI scripts) | git rev-list |
| Need only the commit count | git rev-list --count |
| Need to search file contents in history | git grep |
| Need to find when a specific line was changed | git blame |
| Need to compare two branches' diverged commits | git range-diff or git cherry |
Quick reference
| Filter | Flag | Example |
|---|---|---|
| Time range | --since, --until, --after, --before | --since="2 weeks ago" |
| Author | --author=<pattern> | --author="Jane" |
| Commit message | --grep=<pattern> | --grep="hotfix" |
| Content change | -S<string>, -G<regex> | -S"retryPayment" |
| File path | -- <path> | -- src/payments/ |
| Merge only | --merges / --no-merges | --merges |
| First parent | --first-parent | --first-parent |
| All branches | --all | --all |
| Graph | --graph | --graph --oneline --all |
| Custom format | --format="..." | --format="%h %s" |
Pitfalls
--grepand--authordefault to AND, not OR. If you want commits matching either flag, add--all-matchor use separate commands.--allincludes refs in.git/refs/, not just remote branches. This can surface stale or experimental refs you forgot about.--graphis slow on very large histories. The graph rendering is O(commits) and every commit needs its position calculated. On a 50k-commit repo with many branches,--graphcan take seconds.--sinceis based on committer date, not author date. After a rebase, committer date is reset to "now." Use--author-dateto filter by the original author date.-Sis exact, not fuzzy.-S"retry"does not match"retryPayment"because the literal string"retry"may not appear alone. Use-G"retry"for regex matching.