368

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
  • 10,456
  • 12
  • 40
  • 57
  • 13
    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
  • 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
  • 1
    Don't forget to use `--all` to search in non-ancestor commits :} – user2864740 Sep 20 '18 at 00:16

2 Answers2

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

--git help log

janw
  • 6,628
  • 5
  • 24
  • 44
hobbs
  • 206,796
  • 16
  • 199
  • 282
  • 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
  • 15
    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
  • 6
    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
237
git log --oneline | grep PATTERN
czchen
  • 5,664
  • 2
  • 23
  • 17