From: Dan Moseley <Dan.Moseley@microsoft.com>
To: "peff@peff.net" <peff@peff.net>
Cc: "carenas@gmail.com" <carenas@gmail.com>,
"git@vger.kernel.org" <git@vger.kernel.org>,
"sunshilong369@gmail.com" <sunshilong369@gmail.com>
Subject: RE: How can I search git log with ceratin keyword but without the other keyword?
Date: Sun, 27 Dec 2020 23:45:07 +0000 [thread overview]
Message-ID: <BYAPR21MB1158BDAEA538A78A528B6010E0DA9@BYAPR21MB1158.namprd21.prod.outlook.com> (raw)
In-Reply-To: <BYAPR21MB11587632058438090FE265B8E0DA9@BYAPR21MB1158.namprd21.prod.outlook.com>
Apologies, that was HTML.
From: Dan Moseley
Sent: Sunday, December 27, 2020 3:42 PM
To: peff@peff.net
Cc: carenas@gmail.com; git@vger.kernel.org; sunshilong369@gmail.com
Subject: Re: How can I search git log with ceratin keyword but without the other keyword?
>> I wonder why this command doesn't work well.
>> I intend to find the comment with the keyword "12" but without "comments"
>> whereas the output is something like this:
>>
>> git log --perl-regexp --all-match --grep=12 --grep '\b(?!comments\b)\w+'
>> commit f5b6c3e33bd2559d6976b1d589071a5928992601
>> Author: sunshilong <mailto:sunshilong369@gmail.com>
>> Date: 2020-04-12 23:00:29 +0800
>>
>> comments 2020.04.12 ng
>
>I think this is the thing I was mentioning earlier. That negative
>lookahead means the second one wouldn't match "comments", but it would
>still match "2020.04.12" or "ng". So it won't do what you want.
>
>I can't think of a way to do what you want just a regex, but maybe
>somebody more clever than me can.
git log --perl-regexp --grep='^(?!.*comments).*12.*$'
The first part fails to match if the line contains 'comments' but it does not consume anything, so the second part '.*12.*' begins at the start of the line and matches '12' anywhere in the line.
Of course you can extend the positive and negative parts, e.g.,
git log --perl-regexp --grep='^(?!.*(comments|abc)).*(12|def).*$'
means "lines that don't contain `comments` and don't contain `abc` but do contain `12` or `def`
- Dan
next parent reply other threads:[~2020-12-27 23:46 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <BYAPR21MB11587632058438090FE265B8E0DA9@BYAPR21MB1158.namprd21.prod.outlook.com>
2020-12-27 23:45 ` Dan Moseley [this message]
2020-07-10 4:31 How can I search git log with ceratin keyword but without the other keyword? 孙世龙 sunshilong
2020-07-10 8:14 ` Carlo Arenas
2020-07-11 5:48 ` 孙世龙 sunshilong
2020-07-16 15:31 ` Jeff King
2020-07-17 1:45 ` 孙世龙 sunshilong
2020-07-17 6:33 ` Jeff King
2020-07-17 7:45 ` Junio C Hamano
2020-07-17 10:19 ` Junio C Hamano
2020-07-18 4:51 ` 孙世龙 sunshilong
2020-07-18 18:07 ` Junio C Hamano
2020-07-19 5:28 ` 孙世龙 sunshilong
2020-07-19 8:26 ` Carlo Arenas
2020-07-20 17:50 ` Junio C Hamano
2020-07-22 6:46 ` Carlo Arenas
2020-07-17 10:27 ` 孙世龙 sunshilong
2020-07-17 10:42 ` 孙世龙 sunshilong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=BYAPR21MB1158BDAEA538A78A528B6010E0DA9@BYAPR21MB1158.namprd21.prod.outlook.com \
--to=dan.moseley@microsoft.com \
--cc=carenas@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=sunshilong369@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).