git log is the primary command for reading history. Technically it
traverses the commit graph via git rev-list and prints each commit's
description via git cat-file.
Basic invocation
git log
Prints each commit: SHA, author, date, message. Uses a pager (less) by
default; press q to exit.
Most useful forms
git log --oneline # one line per commit
git log --oneline -10 # last 10
git log --oneline --graph --all # tree of all branches
git log --stat # + summary of changed files
git log -p # + full diff of each commit
git log --follow file.txt # history of one file, tracking renames
The most useful everyday form is --oneline --graph --all --decorate.
Many people set it up as an alias:
git config --global alias.lg "log --oneline --graph --all --decorate"
git lg
Filters
git log --since="2 weeks ago"
git log --until=2026-01-01
git log --author=Linus
git log --grep="fix.*memory" # regex on commit messages
git log -S "deprecated" # commits where this word appeared or disappeared
git log -- src/api.ts # only commits that touched this path
git log main..feature # commits in feature that are not in main
-S (pickaxe) is a particularly powerful filter for finding "when was
this function removed" or "when did this field first appear".
Output formats
git log --pretty=format:"%h %an %s" # short SHA, author, subject
git log --pretty=fuller # both dates: author and committer
git log --format=%H -n 1 # full SHA of the last commit only
--pretty=fuller is especially useful after a rebase to see the
divergence between author date and committer date.
Pitfalls
git log file.txtwithout--followloses history at renames.git log --graphon a large history can become unreadable. Filter by branch or path in that case.- In scripts, prefer
git rev-list(plumbing) overgit log. Its output format is stable.