bashbeginner

Git Log Formatting Tricks

Custom git log formats with graphs, filtering by author, date ranges, and file changes.

bash
# One-line log with graph
git log --oneline --graph --all --decorate

# Custom pretty format
git log --pretty=format:'%C(yellow)%h%Creset %C(green)%ad%Creset | %s %C(red)%d%Creset [%an]' --date=short

# Show only last N commits
git log -10

# Filter by author
git log --author="Alice" --oneline

# Filter by date range
git log --after="2024-01-01" --before="2024-06-30" --oneline

# Show commits that changed a specific file
git log --follow -- src/lib/registry.ts

# Show diff for each commit
git log -p -3  # last 3 commits with full diff

# Show stat summary
git log --stat --oneline -5

# Search commit messages
git log --grep="fix" --oneline

# Search code changes (pickaxe)
git log -S "functionName" --oneline

# Show merge commits only
git log --merges --oneline

# Show commits NOT yet merged to main
git log main..feature-branch --oneline

# Save a git log alias
git config --global alias.lg "log --oneline --graph --all --decorate"

Use Cases

  • Reviewing project history efficiently
  • Finding when a specific change was introduced
  • Generating changelogs and release notes

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.