Git Log Cheat Sheet

Git log mastery — formatting, filtering by author/date/file, pretty formats, graph visualization, searching commits, and log customization.

Last Updated: May 1, 2025

Log Formatting

git log --oneline
One commit per line — SHA + message
git log --graph --oneline --all
Visual branch graph, all branches
git log --oneline --decorate
Show branch/tag labels on commits
git log --pretty=format:'%h %s (%an)'
Custom format: short SHA, subject, author
git log --pretty=format:'%C(auto)%h %s'
Colorized custom format
git log --format=fuller
Show author AND committer details
git log -5
Show only the last 5 commits
git log --since='2 weeks ago'
Show commits from the last 2 weeks

Filtering Commits

git log --author='Name'
Show commits by a specific author
git log --committer='Name'
Filter by committer (may differ from author)
git log --grep='bugfix'
Search commit messages for a keyword
git log --grep='fix' --all-match --grep='login'
AND search: both terms required
git log -- filepath
Show commits that changed a specific file
git log -p filepath
Show full diff alongside commits touching a file
git log -S'function_name'
Pickaxe search: commits that added/removed 'function_name'
git log -G'pattern'
Search commits whose diff contains the pattern

Pretty Format Placeholders

PlaceholderOutputExample
%HFull commit hasha1b2c3d4e5f6...
%hAbbreviated hasha1b2c3d
%sSubject (first line)Fix login bug
%anAuthor nameJane Doe
%aeAuthor email[email protected]
%adAuthor dateMon May 1 2025
%arAuthor date (relative)2 days ago
%dRef names (decorate) (HEAD -> main, origin/main)

Powerful Log Aliases

git log --all --oneline --graph --decorate
Complete visual history (the 'git tree' alias)
git log --stat
Show files changed alongside commit info
git log --shortstat
Compact file change summary
git log --merges
Show only merge commits
git log --no-merges
Exclude merge commits
git log branchA ^branchB
Commits in branchA not in branchB
git log branchA..branchB
Commits in branchB not in branchA (range diff)
git log branchA...branchB
Commits unique to either branch (symmetric diff)
Pro Tip: Bookmark this: `git log --oneline --graph --decorate --all` — a compact visual history of your entire repository.