406

Possible Duplicate:
How to search through all commits in the repository?

Is there a way to search through commit headers using the command line?

Community
  • 1
  • 1
Coderama
  • 11,050
  • 12
  • 44
  • 58
  • 19
    This is not really a duplicate, the other question asks about dangling commits while **this one does not**. Voting to reopen. – sashoalm Feb 10 '15 at 16:43
  • 1
    Ah. But this is a duplicate of [this one](http://stackoverflow.com/questions/7124914/how-to-search-a-git-repository-by-commit-message). While this one is the older question, the newer one has better answers imho. I wish I could revoke my vote to reopen. – cfi Sep 05 '15 at 08:42
  • 2
    Don't forget to use `--all` to search in non-ancestor commits :} – user2864740 Sep 20 '18 at 00:16

2 Answers2

617
git log --grep=<pattern>
    Limit the commits output to ones with log message that matches the 
    specified pattern (regular expression).

from git help log.

Boris Verkhovskiy
  • 14,854
  • 11
  • 100
  • 103
hobbs
  • 223,387
  • 19
  • 210
  • 288
  • 3
    I think this answer is partially wrong, because the `--grep` option searches the whole commit message, instead of just the header. @czchen's answer is more correct, in this case. – pedromanoel Oct 10 '13 at 18:53
  • 16
    except for that fact that czchen's answer requires the use of an external grep utility – david.barkhuizen Oct 03 '14 at 07:22
  • Thank you this helped me a lot, before that I used ack-grep. – Denis Denisov Nov 29 '14 at 14:13
  • 7
    This does not answer OP's question about headers specifically, but it did answer mine about commit messages in general - and not only mine, since it's #1 link in google for "git search commit messages" – Daerdemandt Oct 28 '16 at 18:34
  • Another benefit of this answer is that you can do things like `git log --name-only --grep=foo` if you want more information. – Matt Dec 02 '16 at 22:04
  • 1
    It might also be worth mentioning that this will only search your _local_ repository. – Vyskol Jan 06 '17 at 19:24
  • Is there a way to highlight the pattern? – Martin Thoma Sep 04 '18 at 07:15
  • For those who might make the same mistake that I made: **This DOES work on Windows too!**, so don't look further down for Windows answers. :) – aderchox Jun 27 '22 at 22:09
243
git log --oneline | grep PATTERN
czchen
  • 5,850
  • 2
  • 26
  • 17