Skip to content

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:

  • -S is for tracking a specific identifier across history
  • -G is 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:

PlaceholderOutput
%hAbbreviated commit hash
%HFull commit hash
%sSubject (first line of message)
%bBody (rest of message)
%anAuthor name
%aeAuthor email
%adAuthor date (respects --date=)
%arAuthor date, relative ("2 days ago")
%cnCommitter name (different from author after rebase)
%DRef 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 ago

Graph visualization ​

bash
git log --graph --oneline --all

The --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" --all

Combining 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 ​

SituationUse instead
Need machine-readable output (CI scripts)git rev-list
Need only the commit countgit rev-list --count
Need to search file contents in historygit grep
Need to find when a specific line was changedgit blame
Need to compare two branches' diverged commitsgit range-diff or git cherry

Quick reference ​

FilterFlagExample
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 ​

  • --grep and --author default to AND, not OR. If you want commits matching either flag, add --all-match or use separate commands.
  • --all includes refs in .git/refs/, not just remote branches. This can surface stale or experimental refs you forgot about.
  • --graph is 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, --graph can take seconds.
  • --since is based on committer date, not author date. After a rebase, committer date is reset to "now." Use --author-date to filter by the original author date.
  • -S is exact, not fuzzy. -S"retry" does not match "retryPayment" because the literal string "retry" may not appear alone. Use -G"retry" for regex matching.

Git Master — Git Reference for Every Skill Level