Search Git commits by their messages
Use git log --grep with literal or regular-expression matching, combine message filters, and distinguish message searches from code searches.
Use git log --grep='pattern' to select commits by their commit messages. Add --oneline for a compact list, -i to ignore case, and --all to search history reachable from all local refs rather than only the current branch.
git log --grep='login' --oneline
git log --grep='fix' -i --oneline
git log --grep='^feat' --oneline
git log --all --grep='bug' --oneline
git log --grep='payment' -p
The last command includes patches for the selected commits. The search covers message lines, including the body; ^feat can match a line beginning with feat in the body, not only the subject line.
Choose literal or regular-expression matching
By default, message patterns use basic regular expressions. Use -E for extended expressions or -F for literal strings:
git log -F --grep='JIRA-1234' --oneline
git log -E --grep='fix|repair' --oneline
Quote the pattern so the shell does not expand its special characters. A literal issue identifier search is often easier to reason about than a regular expression.
Combine message filters
Repeated --grep options use OR by default:
git log --grep='bug' --grep='fix' --oneline
Add --all-match when both patterns must match the message:
git log --all-match --grep='bug' --grep='fix' --oneline
The patterns can match different lines of the same message.
Add author and date constraints
git log --grep='refactor' --author='Alex' \
--since='3 months ago' --oneline
Author matching is separate from committer identity. Date boundaries depend on the timestamps and timezone context; use precise timestamps when the reporting window matters.
To count matched commits rather than count formatted output lines:
git rev-list --count --grep='^feat' HEAD
This still uses message-line matching, so use a dedicated subject-only analysis if your definition requires the subject prefix specifically.
FAQ
Does --grep search source code?
No. For changes in a string's occurrence count, use git log -S'functionName'. Use -G'pattern' for matching added or removed diff lines, or git grep with explicit revisions to search snapshot contents.
Does --all contact every remote?
No. It expands local ref coverage. Fetch the relevant remote history first; shallow clones and unavailable refs limit what can be searched.
Why did a message-body match appear under an unrelated subject?
--oneline displays the subject, but --grep can match a different line in the full message. Inspect the commit without --oneline to see the context.
See git-log, git-rev-list, and git-grep.
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan