git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git log -S not finding all commits?
@ 2009-10-08  8:21 Daniel
  2009-10-08  9:12 ` Andreas Ericsson
  2009-10-08 22:02 ` Nanako Shiraishi
  0 siblings, 2 replies; 15+ messages in thread
From: Daniel @ 2009-10-08  8:21 UTC (permalink / raw)
  To: git

Hi,

I did:

$ git version
git version 1.6.4.4
$ mkdir a && cd a && git init
$ echo "Free data" > a
$ git add a
$ git commit -m1
$ echo "Free data allocated by other function" > a
$ git commit -a -m2
$ PAGER=cat git log -S'Free' --oneline
2f34241 1

I would expect "git log" to show both 1 and 2 commit, but it prints only 1.

Is it the correct behavior?

-- 
Daniel

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

* Re: git log -S not finding all commits?
  2009-10-08  8:21 git log -S not finding all commits? Daniel
@ 2009-10-08  9:12 ` Andreas Ericsson
  2009-10-08 11:07   ` Daniel
  2009-10-08 22:02 ` Nanako Shiraishi
  1 sibling, 1 reply; 15+ messages in thread
From: Andreas Ericsson @ 2009-10-08  9:12 UTC (permalink / raw)
  To: Daniel; +Cc: git

On 10/08/2009 10:21 AM, Daniel wrote:
> Hi,
>
> I did:
>
> $ git version
> git version 1.6.4.4
> $ mkdir a&&  cd a&&  git init
> $ echo "Free data">  a
> $ git add a
> $ git commit -m1
> $ echo "Free data allocated by other function">  a
> $ git commit -a -m2
> $ PAGER=cat git log -S'Free' --oneline
> 2f34241 1
>
> I would expect "git log" to show both 1 and 2 commit, but it prints only 1.
>
> Is it the correct behavior?
>

Yes, it's the correct behaviour. -S finds only lines where what you search
for was added or deleted. It counts the number of occurrences of what you
specify in each resulting tree and only shows the commits where that number
changed. In your case, searching for "Free data " would have printed both
commits, since you first introduce that entire string and then remove it.

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.

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

* Re: git log -S not finding all commits?
  2009-10-08  9:12 ` Andreas Ericsson
@ 2009-10-08 11:07   ` Daniel
  2009-10-08 11:40     ` Matthieu Moy
  0 siblings, 1 reply; 15+ messages in thread
From: Daniel @ 2009-10-08 11:07 UTC (permalink / raw)
  To: Andreas Ericsson; +Cc: git

Andreas Ericsson <ae@op5.se> wrote:

> Yes, it's the correct behaviour. -S finds only lines where what you search
> for was added or deleted. It counts the number of occurrences of what you
> specify in each resulting tree and only shows the commits where that number
> changed. In your case, searching for "Free data " would have printed both
> commits, since you first introduce that entire string and then remove it.

Thanks. However, your suggestion doesn't work. It prints only commit 2. Maybe
you meant:

$ PAGER=cat git log --pickaxe-regex -S'Free data$' --oneline

but that doesn't solve my problem. I want to find all commits which changed
lines containing "Free data" (the example I posted is simplified).

Seems I have to use "git log -p" and search its output using pager...

-- 
Daniel

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

* Re: git log -S not finding all commits?
  2009-10-08 11:07   ` Daniel
@ 2009-10-08 11:40     ` Matthieu Moy
  2009-10-08 11:57       ` Matthieu Moy
  0 siblings, 1 reply; 15+ messages in thread
From: Matthieu Moy @ 2009-10-08 11:40 UTC (permalink / raw)
  To: Daniel; +Cc: Andreas Ericsson, git

Daniel <mjucde@o2.pl> writes:

> Andreas Ericsson <ae@op5.se> wrote:
>
>> Yes, it's the correct behaviour. -S finds only lines where what you search
>> for was added or deleted. It counts the number of occurrences of what you
>> specify in each resulting tree and only shows the commits where that number
>> changed. In your case, searching for "Free data " would have printed both
>> commits, since you first introduce that entire string and then remove it.
>
> Thanks. However, your suggestion doesn't work. It prints only commit 2. Maybe
> you meant:
>
> $ PAGER=cat git log --pickaxe-regex -S'Free data$' --oneline
>
> but that doesn't solve my problem. I want to find all commits which changed
> lines containing "Free data" (the example I posted is simplified).
>
> Seems I have to use "git log -p" and search its output using pager...

Search the ML's archives, this is a FAQ. People have proposed an
option to allow log -S to actually search the diff (much slower, but
sometimes what you really want), but AFAIK, no one wrote the code. But
I think someone posted a small perl script along the lines of

git log -p --format="%s\n%x00"  | perl -0 -ne 'print if(/whatever-you-search/);'

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

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

* Re: git log -S not finding all commits?
  2009-10-08 11:40     ` Matthieu Moy
@ 2009-10-08 11:57       ` Matthieu Moy
  2009-10-08 12:49         ` Daniel
  2009-10-08 22:52         ` Randal L. Schwartz
  0 siblings, 2 replies; 15+ messages in thread
From: Matthieu Moy @ 2009-10-08 11:57 UTC (permalink / raw)
  To: Daniel; +Cc: Andreas Ericsson, git

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

> git log -p --format="%s\n%x00"  | perl -0 -ne 'print if(/whatever-you-search/);'

git log -p -z is better than my --format= indeed.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

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

* Re: git log -S not finding all commits?
  2009-10-08 11:57       ` Matthieu Moy
@ 2009-10-08 12:49         ` Daniel
  2009-10-08 18:23           ` Matthieu Moy
  2009-10-08 22:52         ` Randal L. Schwartz
  1 sibling, 1 reply; 15+ messages in thread
From: Daniel @ 2009-10-08 12:49 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: Andreas Ericsson, git

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:

> Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
> 
> > git log -p --format="%s\n%x00"  | perl -0 -ne 'print if(/whatever-you-search/);'
> 
> git log -p -z is better than my --format= indeed.
> 
> -- 
> Matthieu Moy
> http://www-verimag.imag.fr/~moy/
> 

Thanks, it's practically what I was looking for.

-- 
Daniel

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

* Re: git log -S not finding all commits?
  2009-10-08 12:49         ` Daniel
@ 2009-10-08 18:23           ` Matthieu Moy
  0 siblings, 0 replies; 15+ messages in thread
From: Matthieu Moy @ 2009-10-08 18:23 UTC (permalink / raw)
  To: Daniel; +Cc: Andreas Ericsson, git

Daniel <mjucde@o2.pl> writes:

> Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:
>
> > git log -p -z  | perl -0 -ne 'print if(/whatever-you-search/);'
>
> Thanks, it's practically what I was looking for.

http://git.or.cz/gitwiki/GitFaq#A.22gitlog-S.22doesnotshowallcommits

Feel free to improve.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

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

* Re: git log -S not finding all commits?
  2009-10-08  8:21 git log -S not finding all commits? Daniel
  2009-10-08  9:12 ` Andreas Ericsson
@ 2009-10-08 22:02 ` Nanako Shiraishi
  1 sibling, 0 replies; 15+ messages in thread
From: Nanako Shiraishi @ 2009-10-08 22:02 UTC (permalink / raw)
  To: Daniel; +Cc: git

Quoting Daniel <mjucde@o2.pl>

> $ git version
> git version 1.6.4.4
> $ mkdir a && cd a && git init
> $ echo "Free data" > a
> $ git add a
> $ git commit -m1
> $ echo "Free data allocated by other function" > a
> $ git commit -a -m2
> $ PAGER=cat git log -S'Free' --oneline
> 2f34241 1
>
> I would expect "git log" to show both 1 and 2 commit, but it prints only 1.
>
> Is it the correct behavior?

Junio described how various features in git were invented to realize the goal of "Linus's ultimate content tracking" in his blog http://gitster.livejournal.com/35628.html (and he extended on the article in a chapter in his book that was published in Japan last month).

The "pickaxe" search is one of such components. It is meant to be given the block of lines you are interested in the newer version and used to find the commit that changes anything in the given block of lines. For details, see his blog article (item no. 3) at the above URL (and other items as well, if you are interested in learning the history of other notable features).

-- 
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/

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

* Re: git log -S not finding all commits?
  2009-10-08 11:57       ` Matthieu Moy
  2009-10-08 12:49         ` Daniel
@ 2009-10-08 22:52         ` Randal L. Schwartz
  2009-10-09  8:55           ` Matthieu Moy
  1 sibling, 1 reply; 15+ messages in thread
From: Randal L. Schwartz @ 2009-10-08 22:52 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: Daniel, Andreas Ericsson, git

>>>>> "Matthieu" == Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

Matthieu> Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
>> git log -p --format="%s\n%x00"  | perl -0 -ne 'print if(/whatever-you-search/);'

That "if" is noisier than it needs to be:

  perl -0 -ne 'print if /this/'

suffices.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

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

* Re: git log -S not finding all commits?
  2009-10-08 22:52         ` Randal L. Schwartz
@ 2009-10-09  8:55           ` Matthieu Moy
  2009-10-09 12:41             ` Scott Wiersdorf
  2009-10-09 14:07             ` Randal L. Schwartz
  0 siblings, 2 replies; 15+ messages in thread
From: Matthieu Moy @ 2009-10-09  8:55 UTC (permalink / raw)
  To: Randal L. Schwartz; +Cc: Daniel, Andreas Ericsson, git

merlyn@stonehenge.com (Randal L. Schwartz) writes:

>>>>>> "Matthieu" == Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
>
> Matthieu> Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
>>> git log -p --format="%s\n%x00"  | perl -0 -ne 'print if(/whatever-you-search/);'
>
> That "if" is noisier than it needs to be:
>
>   perl -0 -ne 'print if /this/'

Thanks,

Also, this seems to actually print the \0 character. Perhaps a perl
guru can give a simple solution to replace the \0 by a \n?

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

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

* Re: git log -S not finding all commits?
  2009-10-09  8:55           ` Matthieu Moy
@ 2009-10-09 12:41             ` Scott Wiersdorf
  2009-10-09 14:07             ` Randal L. Schwartz
  1 sibling, 0 replies; 15+ messages in thread
From: Scott Wiersdorf @ 2009-10-09 12:41 UTC (permalink / raw)
  To: git

On Fri, Oct 09, 2009 at 10:55:38AM +0200, Matthieu Moy wrote:
> >
> >   perl -0 -ne 'print if /this/'
> 
> Also, this seems to actually print the \0 character. Perhaps a perl
> guru can give a simple solution to replace the \0 by a \n?

If you want some indication that there is a null character:

  perl -0 -ne '/this/ or next; s/\0/{NULL}/g; print'

otherwise:

  perl -0 -ne '/this/ or next; s/\0/\n/g; print'

Scott
-- 
Scott Wiersdorf
<scott@perlcode.org>

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

* Re: git log -S not finding all commits?
  2009-10-09  8:55           ` Matthieu Moy
  2009-10-09 12:41             ` Scott Wiersdorf
@ 2009-10-09 14:07             ` Randal L. Schwartz
  2009-10-09 14:26               ` Matthieu Moy
  2009-10-09 14:33               ` Scott Wiersdorf
  1 sibling, 2 replies; 15+ messages in thread
From: Randal L. Schwartz @ 2009-10-09 14:07 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: Daniel, Andreas Ericsson, git

>>>>> "Matthieu" == Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

Matthieu> merlyn@stonehenge.com (Randal L. Schwartz) writes:
>>>>>>> "Matthieu" == Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
>> 
Matthieu> Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
>>>> git log -p --format="%s\n%x00"  | perl -0 -ne 'print if(/whatever-you-search/);'
>> 
>> That "if" is noisier than it needs to be:
>> 
>> perl -0 -ne 'print if /this/'

Matthieu> Also, this seems to actually print the \0 character. Perhaps a perl
Matthieu> guru can give a simple solution to replace the \0 by a \n?

Just a matter of one more switch.  Sorry for forgetting it earlier.

  .. | perl -ln0e 'print if /this/'

print "Just another Perl hacker,"; # the original

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

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

* Re: git log -S not finding all commits?
  2009-10-09 14:07             ` Randal L. Schwartz
@ 2009-10-09 14:26               ` Matthieu Moy
  2009-10-09 14:28                 ` Randal L. Schwartz
  2009-10-09 14:33               ` Scott Wiersdorf
  1 sibling, 1 reply; 15+ messages in thread
From: Matthieu Moy @ 2009-10-09 14:26 UTC (permalink / raw)
  To: Randal L. Schwartz; +Cc: Daniel, Andreas Ericsson, git

merlyn@stonehenge.com (Randal L. Schwartz) writes:

>   .. | perl -ln0e 'print if /this/'

Ah, good. I would have done this with 3 lines of code, glad to see a
solution with a single more character ;-).

Just updated the FAQ.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

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

* Re: git log -S not finding all commits?
  2009-10-09 14:26               ` Matthieu Moy
@ 2009-10-09 14:28                 ` Randal L. Schwartz
  0 siblings, 0 replies; 15+ messages in thread
From: Randal L. Schwartz @ 2009-10-09 14:28 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: Daniel, Andreas Ericsson, git

>>>>> "Matthieu" == Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

Matthieu> merlyn@stonehenge.com (Randal L. Schwartz) writes:
>> .. | perl -ln0e 'print if /this/'

Matthieu> Ah, good. I would have done this with 3 lines of code, glad to see a
Matthieu> solution with a single more character ;-).

Matthieu> Just updated the FAQ.

And I found that in "perldoc perlrun", because I couldn't remember either. :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

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

* Re: git log -S not finding all commits?
  2009-10-09 14:07             ` Randal L. Schwartz
  2009-10-09 14:26               ` Matthieu Moy
@ 2009-10-09 14:33               ` Scott Wiersdorf
  1 sibling, 0 replies; 15+ messages in thread
From: Scott Wiersdorf @ 2009-10-09 14:33 UTC (permalink / raw)
  To: git

On Fri, Oct 09, 2009 at 07:07:02AM -0700, Randal L. Schwartz wrote:
> 
> Just a matter of one more switch.  Sorry for forgetting it earlier.
> 
>   .. | perl -ln0e 'print if /this/'

And I thought mine was a pretty tidy response... You *are* Japh.

Scott
-- 
Scott Wiersdorf
<scott@perlcode.org>

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

end of thread, other threads:[~2009-10-09 14:40 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-08  8:21 git log -S not finding all commits? Daniel
2009-10-08  9:12 ` Andreas Ericsson
2009-10-08 11:07   ` Daniel
2009-10-08 11:40     ` Matthieu Moy
2009-10-08 11:57       ` Matthieu Moy
2009-10-08 12:49         ` Daniel
2009-10-08 18:23           ` Matthieu Moy
2009-10-08 22:52         ` Randal L. Schwartz
2009-10-09  8:55           ` Matthieu Moy
2009-10-09 12:41             ` Scott Wiersdorf
2009-10-09 14:07             ` Randal L. Schwartz
2009-10-09 14:26               ` Matthieu Moy
2009-10-09 14:28                 ` Randal L. Schwartz
2009-10-09 14:33               ` Scott Wiersdorf
2009-10-08 22:02 ` Nanako Shiraishi

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 NNTP newsgroup(s).