git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* How can I search git log with ceratin keyword but without the other keyword?
@ 2020-07-10  4:31 孙世龙 sunshilong
  2020-07-10  8:14 ` Carlo Arenas
  0 siblings, 1 reply; 17+ messages in thread
From: 孙世龙 sunshilong @ 2020-07-10  4:31 UTC (permalink / raw)
  To: git

Hi, list

How can I search git log with ceratin keyword_a but without keyword_b?

Assume I have a branch master with 3 commits, the comments are t123,
b1 and b12 separately, that is:
b90b03f (HEAD -> master) b12
27f7577 b1
7268b40 t123

And now, I want to use git log --grep to search the log with the
keyword "12" but without t123. The result I want is
b90b03f b12

How can I achieve this?

Thank you for your attention to this matter.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: How can I search git log with ceratin keyword but without the other keyword?
  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
  0 siblings, 1 reply; 17+ messages in thread
From: Carlo Arenas @ 2020-07-10  8:14 UTC (permalink / raw)
  To: 孙世龙 sunshilong; +Cc: git

it is easier to write specific "not match" using PCRE syntax, but
there are several other options to choose from combining as many
expressions as needed from the `git log` man page:

  git log -P --all-match --grep '12' --grep '\b(?!t123\b)\w+'

Carlo

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: How can I search git log with ceratin keyword but without the other keyword?
  2020-07-10  8:14 ` Carlo Arenas
@ 2020-07-11  5:48   ` 孙世龙 sunshilong
  2020-07-16 15:31     ` Jeff King
  0 siblings, 1 reply; 17+ messages in thread
From: 孙世龙 sunshilong @ 2020-07-11  5:48 UTC (permalink / raw)
  To: Carlo Arenas; +Cc: git

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.

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?

Thank you for your help.
Best regards.

On Fri, Jul 10, 2020 at 4:14 PM Carlo Arenas <carenas@gmail.com> wrote:
>
> it is easier to write specific "not match" using PCRE syntax, but
> there are several other options to choose from combining as many
> expressions as needed from the `git log` man page:
>
>   git log -P --all-match --grep '12' --grep '\b(?!t123\b)\w+'
>
> Carlo

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: How can I search git log with ceratin keyword but without the other keyword?
  2020-07-11  5:48   ` 孙世龙 sunshilong
@ 2020-07-16 15:31     ` Jeff King
  2020-07-17  1:45       ` 孙世龙 sunshilong
  0 siblings, 1 reply; 17+ messages in thread
From: Jeff King @ 2020-07-16 15:31 UTC (permalink / raw)
  To: 孙世龙 sunshilong; +Cc: Carlo Arenas, git

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

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: How can I search git log with ceratin keyword but without the other keyword?
  2020-07-16 15:31     ` Jeff King
@ 2020-07-17  1:45       ` 孙世龙 sunshilong
  2020-07-17  6:33         ` Jeff King
  0 siblings, 1 reply; 17+ messages in thread
From: 孙世龙 sunshilong @ 2020-07-17  1:45 UTC (permalink / raw)
  To: Jeff King; +Cc: Carlo Arenas, git

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

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: How can I search git log with ceratin keyword but without the other keyword?
  2020-07-17  1:45       ` 孙世龙 sunshilong
@ 2020-07-17  6:33         ` Jeff King
  2020-07-17  7:45           ` Junio C Hamano
  2020-07-17 10:42           ` 孙世龙 sunshilong
  0 siblings, 2 replies; 17+ messages in thread
From: Jeff King @ 2020-07-17  6:33 UTC (permalink / raw)
  To: 孙世龙 sunshilong; +Cc: Carlo Arenas, git

On Fri, Jul 17, 2020 at 09:45:26AM +0800, 孙世龙 sunshilong wrote:

> 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

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: How can I search git log with ceratin keyword but without the other keyword?
  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-17 10:27             ` 孙世龙 sunshilong
  2020-07-17 10:42           ` 孙世龙 sunshilong
  1 sibling, 2 replies; 17+ messages in thread
From: Junio C Hamano @ 2020-07-17  7:45 UTC (permalink / raw)
  To: Jeff King; +Cc: 孙世龙 sunshilong, Carlo Arenas, git

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/


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: How can I search git log with ceratin keyword but without the other keyword?
  2020-07-17  7:45           ` Junio C Hamano
@ 2020-07-17 10:19             ` Junio C Hamano
  2020-07-18  4:51               ` 孙世龙 sunshilong
  2020-07-17 10:27             ` 孙世龙 sunshilong
  1 sibling, 1 reply; 17+ messages in thread
From: Junio C Hamano @ 2020-07-17 10:19 UTC (permalink / raw)
  To: Jeff King; +Cc: 孙世龙 sunshilong, Carlo Arenas, git

Junio C Hamano <gitster@pobox.com> writes:

> 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.







^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: How can I search git log with ceratin keyword but without the other keyword?
  2020-07-17  7:45           ` Junio C Hamano
  2020-07-17 10:19             ` Junio C Hamano
@ 2020-07-17 10:27             ` 孙世龙 sunshilong
  1 sibling, 0 replies; 17+ messages in thread
From: 孙世龙 sunshilong @ 2020-07-17 10:27 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jeff King, Carlo Arenas, git

Thank you for your reply.

>Perhaps the definition of "distant future" is about 8 years ;-)
>https://lore.kernel.org/git/7vr4q45y65.fsf@alter.siamese.dyndns.org/
I read this post and did the test like this:
git log --grep=12 --grep-and --grep-not \--grep-\(--grep=comments\)
fatal: unrecognized argument: --grep-and

I found it doesn't work for git version 2.7.4.

After reading it carefully again and again, I finally understood what
you mean by
"distant future" is about 8 years. :) (:

Thank you for your attention to this matter.

On Fri, Jul 17, 2020 at 3:45 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> 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/
>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: How can I search git log with ceratin keyword but without the other keyword?
  2020-07-17  6:33         ` Jeff King
  2020-07-17  7:45           ` Junio C Hamano
@ 2020-07-17 10:42           ` 孙世龙 sunshilong
  1 sibling, 0 replies; 17+ messages in thread
From: 孙世龙 sunshilong @ 2020-07-17 10:42 UTC (permalink / raw)
  To: Jeff King; +Cc: Carlo Arenas, git

Hi, Peff

Thank you for your help.

>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.
You have good foresight. :)

>The natural thing to me would be the equivalent of:
>  git grep -e 12 --and --not -e comments
Yes, I intend to achieve this goal. Sorry for misleading you.

>I can't think of a way to do what you want just a regex, but maybe
>somebody more clever than me can.
>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).
Thank you for your patience.
Thanks to your help, I have a better understanding of this matter.

Best Regards
sunshilong

On Fri, Jul 17, 2020 at 2:33 PM Jeff King <peff@peff.net> wrote:
>
> On Fri, Jul 17, 2020 at 09:45:26AM +0800, 孙世龙 sunshilong wrote:
>
> > 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

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: How can I search git log with ceratin keyword but without the other keyword?
  2020-07-17 10:19             ` Junio C Hamano
@ 2020-07-18  4:51               ` 孙世龙 sunshilong
  2020-07-18 18:07                 ` Junio C Hamano
  0 siblings, 1 reply; 17+ messages in thread
From: 孙世龙 sunshilong @ 2020-07-18  4:51 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jeff King, Carlo Arenas, git

Hi, Junio C Hamano

Thank you for your detailed explanation.

>There is not much room for the line-level "--not" operator to
>participate in this picture.
After I have carefully read your explanation again and again.
Maybe, I think there is a way to achieve this goal.
Please point out if there is something wrong.
For details, see below.

>"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.
As you said in your last email, I think it(i.e. check out if a doc has X,
or that does not have Y) could be achieved by this way:
(Please point out if there is something wrong)
1. Split this goal into two parts, one is to find out whether this doc
   has X or not, the other one is whether this doc has Y or not, i.e.
   result = "doc has X" && "doc has no Y".
   We can run the grep machinery twice to achieve this goal.
2. As what you said in your last email, I have no much doubt about
    how to find out whether the doc has X or not. But, maybe, we can
    do some improvement.
    We can record the number of each line which matches the criteria(
    i.e. this line has X). We use "resX" to represent the result of this
    step(e.g: line 5,6,9,10 has X).
3. Check out whether each line matches the criteria(i.e. not have Y) or
    not and record the number of each line.
    We use "resY" to represent the result of this step(e.g. line 1, 5, 9,
    has no Y).
4. If resX is a non-empty set and resY is full set(i.e. contains all the
    line number) ,it implies that doc "have X and not have Y".

    Thank you for your attention to this matter.
    Best Regards.
    Sunshilong(孙世龙)

On Fri, Jul 17, 2020 at 6:19 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Junio C Hamano <gitster@pobox.com> writes:
>
> > 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.
>
>
>
>
>
>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: How can I search git log with ceratin keyword but without the other keyword?
  2020-07-18  4:51               ` 孙世龙 sunshilong
@ 2020-07-18 18:07                 ` Junio C Hamano
  2020-07-19  5:28                   ` 孙世龙 sunshilong
  0 siblings, 1 reply; 17+ messages in thread
From: Junio C Hamano @ 2020-07-18 18:07 UTC (permalink / raw)
  To: 孙世龙 sunshilong; +Cc: Jeff King, Carlo Arenas, git

孙世龙 sunshilong <sunshilong369@gmail.com> writes:

> Thank you for your detailed explanation.
>
>>There is not much room for the line-level "--not" operator to
>>participate in this picture.
> After I have carefully read your explanation again and again.
> Maybe, I think there is a way to achieve this goal.
> Please point out if there is something wrong.

Sorry, it is currently not in the area of interest for me to examine
an extensive rewrite of the "grep" machinery for unknown benefit.
The cost-benefit ratio does not look too great to just add "X && !Y"
support to existing "X && Y" logic.  If we were seriously extending
the machinery, I'd rather see us shooting for even more generic
boolean expression support, not just "our --all-match currently
requires all of the AND-ed terms to positively match, but lets make
it possible to require some of these terms not to fire at all".


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: How can I search git log with ceratin keyword but without the other keyword?
  2020-07-18 18:07                 ` Junio C Hamano
@ 2020-07-19  5:28                   ` 孙世龙 sunshilong
  2020-07-19  8:26                     ` Carlo Arenas
  0 siblings, 1 reply; 17+ messages in thread
From: 孙世龙 sunshilong @ 2020-07-19  5:28 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jeff King, Carlo Arenas, git

Hi,

>Sorry, it is currently not in the area of interest for me to examine
>an extensive rewrite of the "grep" machinery for unknown benefit.
>The cost-benefit ratio does not look too great to just add "X && !Y"
>support to existing "X && Y" logic.  If we were seriously extending
>the machinery, I'd rather see us shooting for even more generic
>boolean expression support, not just "our --all-match currently
>requires all of the AND-ed terms to positively match, but lets make
>it possible to require some of these terms not to fire at all".
I see. Maybe, there is a workaround method to achieve this goal(
i.e. X&&!Y) without rewriting the "grep" machinery.
Is there some method(or command provided by git) that could get the
comments of a certain commitment(e.g: first, second,... nth) other than
getting the last several comments by "git log -n"?
So if there is an answer to this question, we can achieve that goal by shell
script and git commands.

My answer to this question is:
git log -n 1 --skip certain_number

Is there some command that could better achieve this goal?

Thank you for your attention to this matter.

On Sun, Jul 19, 2020 at 2:07 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> 孙世龙 sunshilong <sunshilong369@gmail.com> writes:
>
> > Thank you for your detailed explanation.
> >
> >>There is not much room for the line-level "--not" operator to
> >>participate in this picture.
> > After I have carefully read your explanation again and again.
> > Maybe, I think there is a way to achieve this goal.
> > Please point out if there is something wrong.
>
> Sorry, it is currently not in the area of interest for me to examine
> an extensive rewrite of the "grep" machinery for unknown benefit.
> The cost-benefit ratio does not look too great to just add "X && !Y"
> support to existing "X && Y" logic.  If we were seriously extending
> the machinery, I'd rather see us shooting for even more generic
> boolean expression support, not just "our --all-match currently
> requires all of the AND-ed terms to positively match, but lets make
> it possible to require some of these terms not to fire at all".
>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: How can I search git log with ceratin keyword but without the other keyword?
  2020-07-19  5:28                   ` 孙世龙 sunshilong
@ 2020-07-19  8:26                     ` Carlo Arenas
  2020-07-20 17:50                       ` Junio C Hamano
  0 siblings, 1 reply; 17+ messages in thread
From: Carlo Arenas @ 2020-07-19  8:26 UTC (permalink / raw)
  To: 孙世龙 sunshilong; +Cc: Junio C Hamano, Jeff King, git

On Sat, Jul 18, 2020 at 10:28 PM 孙世龙 sunshilong <sunshilong369@gmail.com> wrote:
> Is there some method(or command provided by git) that could get the
> comments of a certain commit (e.g: first, second,... nth)

what you are looking for is described sometimes as "relative
reference" [1], so for example if you want to refer to the commit
before last (ex: second from the top, counting as 0 base) in a
repository that looks like:

$ git log --oneline
b1824b2 (HEAD -> master) second
00d85f1 first
68757c9 initial

$ git log --oneline -n 1 HEAD@{1}
00d85f1 first

Carlo

[1] https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E9%80%89%E6%8B%A9%E4%BF%AE%E8%AE%A2%E7%89%88%E6%9C%AC

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: How can I search git log with ceratin keyword but without the other keyword?
  2020-07-19  8:26                     ` Carlo Arenas
@ 2020-07-20 17:50                       ` Junio C Hamano
  2020-07-22  6:46                         ` Carlo Arenas
  0 siblings, 1 reply; 17+ messages in thread
From: Junio C Hamano @ 2020-07-20 17:50 UTC (permalink / raw)
  To: Carlo Arenas; +Cc: 孙世龙 sunshilong, Jeff King, git

Carlo Arenas <carenas@gmail.com> writes:

> On Sat, Jul 18, 2020 at 10:28 PM 孙世龙 sunshilong <sunshilong369@gmail.com> wrote:
>> Is there some method(or command provided by git) that could get the
>> comments of a certain commit (e.g: first, second,... nth)
>
> what you are looking for is described sometimes as "relative
> reference" [1], so for example if you want to refer to the commit
> before last (ex: second from the top, counting as 0 base) in a
> repository that looks like:
>
> $ git log --oneline
> b1824b2 (HEAD -> master) second
> 00d85f1 first
> 68757c9 initial
>
> $ git log --oneline -n 1 HEAD@{1}
> 00d85f1 first

You meant HEAD~1, not the nth reflog entry (which does not have
anything to do with the parenthood sequence between commits).



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: How can I search git log with ceratin keyword but without the other keyword?
  2020-07-20 17:50                       ` Junio C Hamano
@ 2020-07-22  6:46                         ` Carlo Arenas
  0 siblings, 0 replies; 17+ messages in thread
From: Carlo Arenas @ 2020-07-22  6:46 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: 孙世龙 sunshilong, Jeff King, git

On Mon, Jul 20, 2020 at 10:50 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Carlo Arenas <carenas@gmail.com> writes:
> > repository that looks like:
> >
> > $ git log --oneline
> > b1824b2 (HEAD -> master) second
> > 00d85f1 first
> > 68757c9 initial
> >
> > $ git log --oneline -n 1 HEAD@{1}
> > 00d85f1 first
>
> You meant HEAD~1, not the nth reflog entry (which does not have
> anything to do with the parenthood sequence between commits).

indeed, thanks you; and for more documentation in the syntax of those
"revisions" :

  https://git-scm.com/docs/gitrevisions

Carlo

^ permalink raw reply	[flat|nested] 17+ messages in thread

* RE: How can I search git log with ceratin keyword but without the other keyword?
       [not found] <BYAPR21MB11587632058438090FE265B8E0DA9@BYAPR21MB1158.namprd21.prod.outlook.com>
@ 2020-12-27 23:45 ` Dan Moseley
  0 siblings, 0 replies; 17+ messages in thread
From: Dan Moseley @ 2020-12-27 23:45 UTC (permalink / raw)
  To: peff@peff.net
  Cc: carenas@gmail.com, git@vger.kernel.org, sunshilong369@gmail.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?


>> 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


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2020-12-27 23:47 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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).