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
Jeff King <peff@peff.net>
Date
Jul 17, 2020, 06:33 UTC
Message-ID
<20200717063324.GB1179001@coredump.intra.peff.net>
In-Reply-To
<CAAvDm6Z6SA8rYYHaFT=APBSx0tM+5rHseP+fRLufgDxvEthsww@mail.gmail.com>
On Fri, Jul 17, 2020 at 09:45:26AM +0800, 孙世龙 sunshilong wrote:
Show 10 quoted lines
> 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

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.

The natural thing to me would be the equivalent of:
  git grep -e 12 --and --not -e comments

The underlying grep machinery in Git understands how to compose multiple patterns like this, and the command above really does work (though of course it is searching for lines in a file and not commit messages).

But none of that is exposed via the command-line of "git log". I think it would be possible to do so, but I'm not sure how tricky it would be (certainly one complication is that "--not" already means something else there, but presumably we could have "--grep-and", "--grep-not", etc).

-Peff
Previous: 孙世龙 sunshilongNext: Junio C Hamano
Message 6 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.