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
DMDan Moseley <dan.moseley@microsoft.com>
Date
Dec 27, 2020, 23:45 UTC
Message-ID
<BYAPR21MB1158BDAEA538A78A528B6010E0DA9@BYAPR21MB1158.namprd21.prod.outlook.com>
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?
Show 17 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 <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
Message 1 of 1 in “RE: How can I search git log with ceratin keyword but without the other keyword?”
  1. Dan MoseleyDec 27, 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.