Re: How can I search git log with ceratin keyword but without the other keyword?
- From
Jeff King <peff@peff.net>
- Date
- Jul 16, 2020, 15:31 UTC
- Message-ID
- <20200716153159.GA1061124@coredump.intra.peff.net>
- In-Reply-To
- <CAAvDm6avvkXrU-Q8zu7C5WFqfCbf0DN=6cPMU-rOxgmdAh1Ebw@mail.gmail.com>
On Sat, Jul 11, 2020 at 01:48:04PM +0800, 孙世龙 sunshilong wrote:
Show 7 quoted lines
> Thank you for taking the time to respond to me. > > When I run the said shell command, this error reported: > # git log -P --all-match --grep '12' --grep '\b(?!t123\b)\w+' > fatal: unrecognized argument: -P > > The version of git which I am currently using is 2.7.4.
Try replacing "-P" with "--perl-regexp"; the shorter name was added in v2.14.0. You'll also need a version of Git built with libpcre support. If it's not, you'll get a message like:
$ git log --perl-regexp --all-match --grep=12 --grep '\b(?!t123\b)\w+' fatal: cannot use Perl-compatible regexes when not compiled with USE_LIBPCRE
> One more question, could you please explain '\b(?!t123\b)\w+' in > more detail for me? > Or suggest some related documents for me to go through?
The (?!...) block is a negative lookahead assertion in perl-compatible regular expressions. So it's looking for a word boundary (\b) _not_ followed by t123.
I'm not sure if that solves your original problem, though. It won't match "t123", but presumably there are other words in that commit message.
A negative lookbehind like:
git log --perl-regexp --grep='(?<!t)12'
might work, if the distinction between "b12" and "t123" is important. Or if you care about "12" but not "123", then maybe just asking for a word boundary at the end would work:
--grep='12\b'
-Peff