418

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

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

3
  • 21
    This is not really a duplicate, the other question asks about dangling commits while this one does not. Voting to reopen.
    – sashoalm
    Commented Feb 10, 2015 at 16:43
  • 1
    Ah. But this is a duplicate of this one. While this one is the older question, the newer one has better answers imho. I wish I could revoke my vote to reopen.
    – cfi
    Commented Sep 5, 2015 at 8:42
  • 2
    Don't forget to use --all to search in non-ancestor commits :} Commented Sep 20, 2018 at 0:16

2 Answers 2

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

from git help log.

8
  • 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. Commented Oct 10, 2013 at 18:53
  • 16
    except for that fact that czchen's answer requires the use of an external grep utility Commented Oct 3, 2014 at 7:22
  • Thank you this helped me a lot, before that I used ack-grep. Commented Nov 29, 2014 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" Commented Oct 28, 2016 at 18:34
  • 1
    It might also be worth mentioning that this will only search your local repository.
    – Vyskol
    Commented Jan 6, 2017 at 19:24
249
git log --oneline | grep PATTERN
5
  • 24
    Won't this miss commits with the PATTERN in the commit message's lines other than the first?
    – tutuDajuju
    Commented Jan 21, 2014 at 12:26
  • 20
    requires grep to be available, i.e. this is a linux / git bash specific solution (unless you've installed grep on windows) Commented Oct 3, 2014 at 7:05
  • 8
    If you're on windows, or some other env. without grep, combine both answers: git log --oneline --grep=PATTERN
    – user151841
    Commented Apr 30, 2019 at 13:21
  • @tutuDajuju no, the line breaks are just replaced with spaces
    – bb1950328
    Commented Oct 21, 2020 at 17:20
  • another point to note is that if you are using strings within commit messages don't forget to add the ignore case flag like this in end. git log --oneline | grep PATTERN -i Commented Feb 20 at 6:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.