Ad space (banner)
🌿Git Lessons
Lesson 48 / 59

Searching Commit Messages with git log --grep

This lesson is for anyone who wants to find only commits containing a specific keyword, using git log --grep="fix". git log --grep searches commit messages and lists only the ones that match.

Use it in the form git log --grep=pattern. The pattern can be a plain string or a regular expression, and you can combine it with the case-insensitive -i flag or the multi-condition AND search --all-match.

Running git log --grep="fix" shows only the history entries whose commit message contains "fix." Handy when you want to round up just the bug-fix commits.

A common early mistake is reaching for --grep when you actually want to search the change content (the diff), not the commit message — for searching inside a diff, you'd want the -S or -G option instead.

In real practice, this command is used routinely for investigative work like "find commits referencing a certain ticket number" or "trace the fix history for a specific feature."

Git
Try it (type this into the pseudo terminal)
git log --grep="fix"

🧑‍💻 You can type this command into the Git pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)