How to search commit messages in Git
Finding commits related to specific features, bugs, or changes becomes challenging as your repository history grows to hundreds or thousands of commits. As the creator of CoreUI with over 25 years of software development experience, I regularly search through extensive commit histories to track down changes. Git log provides powerful filtering options to search commit messages for specific keywords, patterns, or ticket numbers. This approach quickly identifies relevant commits without manually reviewing the entire history.
Use git log --grep to search commit messages for specific patterns or keywords.
# Search for commits containing keyword
git log --grep='fix'
# Case-insensitive search
git log --grep='bug' -i
# Search for multiple patterns (OR)
git log --grep='feature' --grep='enhancement'
# Search for all patterns (AND)
git log --grep='auth' --grep='security' --all-match
# Search with regex
git log --grep='ISSUE-[0-9]+'
# Search in specific branch
git log main --grep='refactor'
# Show one-line summary
git log --oneline --grep='update'
# Search by author and message
git log --author='John' --grep='api'
# Search commit messages and show patches
git log -p --grep='password'
# Search since specific date
git log --since='2025-01-01' --grep='security'
# Exclude commits with pattern
git log --grep='WIP' --invert-grep
# Search and show specific format
git log --grep='merge' --pretty=format:'%h %s %an'
Best Practice Note
The --grep flag searches commit message text only, not file changes. For searching actual code changes, combine with -S (pickaxe) option: git log -S'functionName' --grep='refactor'. Use --all-match when you need all grep patterns to match instead of any. The --invert-grep flag excludes matching commits, useful for filtering out WIP or merge commits. This is how we navigate CoreUI development history—searching for ticket numbers, feature keywords, and bug references to understand when and why specific changes were made across years of development.



