Issue
(I'm using Windows 10 and git-bash)
I'm looking for all merge commits that have this grep pattern in the message
Merged PR \d{5}"
git log --grep "Merged PR \d{5}"
Nothing is returned.
However this pattern works "Merged PR \d*"
git log --grep "Merged PR \d*"
Other examples that do not seem to work
git log --merges --grep='Merged PR \d+'
git log --merges --grep='Merged\sPR\s\d+:\s(?!merg)'
The documentation does not give examples: https://www.git-scm.com/docs/git-log
I've also tried setting these configs
git config --global grep.extendRegexp true
git config --global grep.lineNumber true
What regex expressions are allowed in git-log --grep ?
Solution
The documentation for git grep
mentions support for four different variants:
Variant | command line option | grep.patternType configuration option |
---|---|---|
Fixed Strings (i.e. no pattern) | --fixed-strings |
fixed |
Basic Regular Expression (BRE) | --basic-regexp |
basic |
Extended Regular Expression (ERE) | --extended-regexp |
extended |
Perl Compatible Regular Expression (PCRE) | --perl-regexp |
perl |
Default | N/A | default or unset |
What the default setting is depends on the setting of the grep.extendedRegexp
configuration option: Extended Regular Expression if set to true
, Basic Regular Expression otherwise. (Note that this option only has an effect if grep.patternType
is default
or unset, otherwise it is ignored.)
A different way of saying this is that grep
ing in Git works just like grep
: Basic Regular Expressions by default, but you can switch to Extended Regular Expressions explicitly. In fact, that is how pretty much any Unix utility that accepts Regexps works, with the addition that Git also supports PCREs.
The same command line options are also documented in the documentation for git log
:
--basic-regexp
: Consider the limiting patterns to be basic regular expressions; this is the default.-E
/--extended-regexp
: Consider the limiting patterns to be extended regular expressions instead of the default basic regular expressions.-F
/--fixed-strings
: Consider the limiting patterns to be fixed strings (don’t interpret pattern as a regular expression).-P
/--perl-regexp
: Consider the limiting patterns to be Perl-compatible regular expressions. Support for these types of regular expressions is an optional compile-time dependency. If Git wasn’t compiled with support for them providing this option will cause it to die.
Answered By - Jörg W Mittag Answer Checked By - Robin (WPSolving Admin)