Beyond the default
git log is a small query language for your history. With the right flags it produces dashboard-quality reports, audit trails, and bug forensics. This page collects the most useful incantations.
Pretty formats
git log --pretty=oneline
git log --pretty=fuller
git log --pretty=format:'%h %ad %an %s' --date=short
git log --pretty=format:'%C(yellow)%h%Creset %C(cyan)%ad%Creset %s %C(green)(%an)%Creset' --date=short
Define a permanent alias:
git config --global alias.lg "log --pretty=format:'%C(auto)%h %ad %s %d' --date=short --graph"
Graph view
git log --graph --oneline --all --decorate
git log --graph --first-parent main
--first-parent hides feature-branch noise, showing only integration history on main.
Filtering by content
Pickaxe finds commits that changed an occurrence count of a string:
git log -S"FunctionName" # commits that add/remove the literal
git log -G"regex.*pattern" # commits whose diff matches the regex
git log -L :myFunc:src/file.c # function evolution
git log -L 100,150:src/file.c # line range evolution
Filtering by metadata
git log --since=2.weeks --until=yesterday
git log --author='Alice'
git log --grep='hotfix' --grep='security' --all-match
git log --no-merges
git log --merges --first-parent main
git log --committer='@example.com'
Path-restricted log
git log -- src/parser/
git log --diff-filter=D -- secrets.env # commits that deleted a file
git log --follow -- src/old/path.go # follow renames
Counting and stats
git shortlog -sne # commits per author
git log --stat
git log --shortstat
git log --numstat
Walks
git log --ancestry-path A..B
git log --boundary --left-right A...B
git log --reverse # chronological order
git log --topo-order
git log --date-order
Common mistakes
Using --all when you mean --branches — --all includes tags, remotes, and stash, which can dramatically expand output. Forgetting --follow on renamed files. Confusing A..B (in B, not A) with A...B (symmetric difference). The pickaxe (-S/-G) only sees the textual diff; for semantic searches, combine with --diff-filter.
Range-diff for series
Compare two versions of a patch series:
git range-diff main..topic-v1 main..topic-v2
See "Git range-diff: comparing revision series".
Related
See "Three-way diff and conflict resolution strategies" and "Git notes: attaching metadata to commits".