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
- Search commit messages:
git log --grep="bugfix"
- Search by author:
git log --author="Alice"
- Search code changes (pickaxe):
git log -S "function_name"
- Search with regex:
git log --grep="fix|patch" --extended-regexp
Tips
-Guses regex for code changes, unlike-Swhich uses exact string match.- Combine filters:
git log --author="Alice" --grep="fix". - Use
--allto search across all branches.
Common issues
- Case sensitivity: add
-ifor case-insensitive search. - Very old history: use
--sinceand--untilto narrow the date range.