Last Updated: May 1, 2025
Log Formatting
git log --onelineOne commit per line — SHA + message
git log --graph --oneline --allVisual branch graph, all branches
git log --oneline --decorateShow 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=fullerShow author AND committer details
git log -5Show 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 -- filepathShow commits that changed a specific file
git log -p filepathShow 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
| Placeholder | Output | Example |
|---|---|---|
| %H | Full commit hash | a1b2c3d4e5f6... |
| %h | Abbreviated hash | a1b2c3d |
| %s | Subject (first line) | Fix login bug |
| %an | Author name | Jane Doe |
| %ae | Author email | [email protected] |
| %ad | Author date | Mon May 1 2025 |
| %ar | Author date (relative) | 2 days ago |
| %d | Ref names (decorate) | (HEAD -> main, origin/main) |
Powerful Log Aliases
git log --all --oneline --graph --decorateComplete visual history (the 'git tree' alias)
git log --statShow files changed alongside commit info
git log --shortstatCompact file change summary
git log --mergesShow only merge commits
git log --no-mergesExclude merge commits
git log branchA ^branchBCommits in branchA not in branchB
git log branchA..branchBCommits in branchB not in branchA (range diff)
git log branchA...branchBCommits unique to either branch (symmetric diff)
Pro Tip: Bookmark this: `git log --oneline --graph --decorate --all` — a compact visual history of your entire repository.