git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How can I search git log with ceratin keyword but without the other keyword?

From
孙S孙世龙 sunshilong <sunshilong369@gmail.com>
Date
Jul 17, 2020, 01:45 UTC
Message-ID
<CAAvDm6Z6SA8rYYHaFT=APBSx0tM+5rHseP+fRLufgDxvEthsww@mail.gmail.com>
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:
Show 41 quoted lines
>
> 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
Previous: Jeff KingNext: Jeff King
Message 5 of 16 in “How can I search git log with ceratin keyword but without the other keyword?”
  1. 孙世龙 sunshilongJul 10, 2020
  2. Carlo ArenasJul 10, 2020
  3. 孙世龙 sunshilongJul 11, 2020
  4. Jeff KingJul 16, 2020
  5. 孙世龙 sunshilongJul 17, 2020
  6. Jeff KingJul 17, 2020
  7. Junio C HamanoJul 17, 2020
  8. Junio C HamanoJul 17, 2020
  9. 孙世龙 sunshilongJul 18, 2020
  10. Junio C HamanoJul 18, 2020
  11. 孙世龙 sunshilongJul 19, 2020
  12. Carlo ArenasJul 19, 2020
  13. Junio C HamanoJul 20, 2020
  14. Carlo ArenasJul 22, 2020
  15. 孙世龙 sunshilongJul 17, 2020
  16. 孙世龙 sunshilongJul 17, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.