How to search commit history in Git

· Category: Git

Short answer

Use git log with options like --grep, --author, and -S to search commit messages, authors, and code changes.

Steps

  1. Search commit messages:
git log --grep="bugfix"
  1. Search by author:
git log --author="Alice"
  1. Search code changes (pickaxe):
git log -S "function_name"
  1. Search with regex:
git log --grep="fix|patch" --extended-regexp

Tips

  • -G uses regex for code changes, unlike -S which uses exact string match.
  • Combine filters: git log --author="Alice" --grep="fix".
  • Use --all to search across all branches.

Common issues

  • Case sensitivity: add -i for case-insensitive search.
  • Very old history: use --since and --until to narrow the date range.