git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "孙世龙 sunshilong" <sunshilong369@gmail.com>
To: Jeff King <peff@peff.net>
Cc: Carlo Arenas <carenas@gmail.com>, git@vger.kernel.org
Subject: Re: How can I search git log with ceratin keyword but without the other keyword?
Date: Fri, 17 Jul 2020 09:45:26 +0800	[thread overview]
Message-ID: <CAAvDm6Z6SA8rYYHaFT=APBSx0tM+5rHseP+fRLufgDxvEthsww@mail.gmail.com> (raw)
In-Reply-To: <20200716153159.GA1061124@coredump.intra.peff.net>

Thank you for your detailed explanation.
My understanding of this matter is at a different level with your help.

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 <sunshilong369@gmail.com>
Date:   2020-04-12 23:00:29 +0800

    comments 2020.04.12 ng

Thank you for your attention to this matter.

On Thu, Jul 16, 2020 at 11:32 PM Jeff King <peff@peff.net> wrote:
>
> On Sat, Jul 11, 2020 at 01:48:04PM +0800, 孙世龙 sunshilong wrote:
>
> > 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

  reply	other threads:[~2020-07-17  1:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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
     [not found] <BYAPR21MB11587632058438090FE265B8E0DA9@BYAPR21MB1158.namprd21.prod.outlook.com>
2020-12-27 23:45 ` Dan Moseley

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAAvDm6Z6SA8rYYHaFT=APBSx0tM+5rHseP+fRLufgDxvEthsww@mail.gmail.com' \
    --to=sunshilong369@gmail.com \
    --cc=carenas@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).