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
Junio C Hamano <gitster@pobox.com>
Date
Jul 17, 2020, 10:19 UTC
Message-ID
<xmqq7dv2fnpb.fsf@gitster.c.googlers.com>
In-Reply-To
<xmqqd04ufutq.fsf@gitster.c.googlers.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 10 quoted lines
> Jeff King <peff@peff.net> writes:
>
>> 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).
>
> Perhaps the definition of "distant future" is about 8 years ;-)
>
> https://lore.kernel.org/git/7vr4q45y65.fsf@alter.siamese.dyndns.org/

Having said that, I do not think our underlying grep machinery is equipped to answer "find every commit whose log message has X but not Y", even if we exposed the interface that is equivalent to that of "git grep" to "git log".

There are two levels of boolean combination involved in running our "grep" machinery. The lower level is used to determine if each line matches the criteria. The main consumer of the "grep" machinery is of course "git grep" and because it is line oriented, we have quite a rich set of operations and combinations to say things like "if a line has X and Y on it in any order, but not Z on it, then the line is a match." That is what "--not", "--and", "--or" (not exposed to the "git log" interface) express and we even take "(" and ")" for grouping, e.g. "( X --or Y ) --and --not Z".

Another level of combination is to determine if the entire document matches. It often happens that you want to find a document with both X and Y in it, and "grep -e X --and -e Y" is *NOT* a way to do so---the "--and" is a line-level combinator and tells the machinery to find lines that have both X and Y on them.

We have a fairly ad-hoc single mechanism for boolean combination at this level and that is the "--all-match" option, which says "Look at the boolean expression you used to find each matching line, and separate them at the OR operator at the top level. Now, apply the matching logic to all lines in a document and see if _all_ the clauses joined by the top-level OR operators matched at least once. If yes, then the document matches."

That is how "git grep --all-match -e X -e Y" finds documents that refer to both X and Y but not necessarily on the same line.

There is not much room for the line-level "--not" operator to participate in this picture. "git grep -e X --not -e Y" would mean "find lines that has X, or that does not have Y", so as long as a document has one line with X on it and one line (which can be but does not have to be the same line) that does not have Y on it, the variant of that search with "--all-match" in it would say "yup the doc matches". But that is definitely not what the user who wants to say "if a doc has X in it, I want to see it, but I do not want to see it if it also has Y" wants to see.

Previous: Junio C HamanoNext: 孙世龙 sunshilong
Message 8 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.