Git Log Formatting: Custom Formats, Graphs, and Filters
Master git log with custom formats, graph visualization, date filters, author filters, and search. Build the perfect log view for your workflow.
Log / History
Detailed Explanation
Mastering Git Log Output
git log is far more powerful than its default output suggests. With formatting options and filters, you can build exactly the view you need.
Essential Log Formats
# One-line compact format
git log --oneline
# Graph view with branch visualization
git log --graph --oneline --all --decorate
# Show changed files per commit
git log --stat
# Show full diff per commit
git log -p
# Last N commits
git log -5
Custom Pretty Format
# Custom format with colors
git log --pretty=format:"%C(yellow)%h%C(reset) %C(blue)%ad%C(reset) %C(green)%an%C(reset) %s" --date=short
# Format tokens:
# %H - full hash %h - short hash
# %an - author name %ae - author email
# %ad - author date %ar - relative date
# %cn - committer name %s - subject
# %b - body %d - decorations
Filtering Commits
# By author
git log --author="Jane"
# By date range
git log --since="2025-01-01" --until="2025-06-30"
# By commit message
git log --grep="fix:" --oneline
# Commits that modified a specific file
git log -- src/auth.ts
# Commits that added or removed a string
git log -S "TODO" --oneline
Useful Aliases
# Beautiful graph log
git config --global alias.lg "log --graph --oneline --all --decorate"
# Recent commits by me
git config --global alias.my "log --author='$(git config user.name)' --oneline -20"
# Commits in the last week
git config --global alias.week "log --since='1 week ago' --oneline"
Comparing Branches
# Commits on feature not on main
git log main..feature --oneline
# Commits on either branch but not both
git log main...feature --oneline
# Commits on main since branching
git log feature..main --oneline
Use Case
Effective use of git log is essential for code review, debugging, and understanding project evolution. Custom log formats save time when you need specific information. The graph view is invaluable for understanding complex branching patterns. Date and author filters help track down when and by whom specific changes were made. Setting up log aliases is one of the first things experienced developers do on a new machine.