threads / discuss / 21155

git log -S not finding all commits?

Subject: git log -S not finding all commits?

## tl;dr

15 messages between Oct 8, 2009 and Oct 9, 2009.

replies: 14people: 6as markdown or json

Daniel· Oct 8, 2009, 08:21 UTC · lore
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
Andreas Ericsson· Oct 8, 2009, 09:12 UTC · re: Daniel · lore

Re: git log -S not finding all commits?

On 10/08/2009 10:21 AM, Daniel wrote:
Show 19 quoted lines
> 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.
Daniel· Oct 8, 2009, 11:07 UTC · re: Andreas Ericsson · lore

Re: git log -S not finding all commits?

Andreas Ericsson <ae@op5.se> wrote:
Show 5 quoted lines
> 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
Matthieu Moy· Oct 8, 2009, 11:40 UTC · re: Daniel · lore

Re: git log -S not finding all commits?

Daniel <mjucde@o2.pl> writes:
Show 17 quoted lines
> 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/
Matthieu Moy· Oct 8, 2009, 11:57 UTC · re: Matthieu Moy · lore

Re: git log -S not finding all commits?

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/
Daniel· Oct 8, 2009, 12:49 UTC · re: Matthieu Moy · lore

Re: git log -S not finding all commits?

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:
Show 10 quoted lines
> 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
Matthieu Moy· Oct 8, 2009, 18:23 UTC · re: Daniel · lore

Re: git log -S not finding all commits?

Daniel <mjucde@o2.pl> writes:
Show 5 quoted lines
> 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/
Randal L. Schwartz· Oct 8, 2009, 22:52 UTC · re: Matthieu Moy · lore

Re: git log -S not finding all commits?

>>>>> "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
Matthieu Moy· Oct 9, 2009, 08:55 UTC · re: Randal L. Schwartz · lore

Re: git log -S not finding all commits?

merlyn@stonehenge.com (Randal L. Schwartz) writes:
Show 8 quoted lines
>>>>>> "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/
Scott Wiersdorf· Oct 9, 2009, 12:41 UTC · re: Matthieu Moy · lore

Re: git log -S not finding all commits?

On Fri, Oct 09, 2009 at 10:55:38AM +0200, Matthieu Moy wrote:
Show 5 quoted lines
> >
> >   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>
Randal L. Schwartz· Oct 9, 2009, 14:07 UTC · re: Matthieu Moy · lore

Re: git log -S not finding all commits?

>>>>> "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:
Show 5 quoted lines
>>>> 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
Matthieu Moy· Oct 9, 2009, 14:26 UTC · re: Randal L. Schwartz · lore

Re: git log -S not finding all commits?

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/
Randal L. Schwartz· Oct 9, 2009, 14:28 UTC · re: Matthieu Moy · lore

Re: git log -S not finding all commits?

>>>>> "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
Scott Wiersdorf· Oct 9, 2009, 14:33 UTC · re: Randal L. Schwartz · lore

Re: git log -S not finding all commits?

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>
Nanako Shiraishi· Oct 8, 2009, 22:02 UTC · re: Daniel · lore

Re: git log -S not finding all commits?

Quoting Daniel <mjucde@o2.pl>
Show 14 quoted lines
> $ 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/

← back to recent threads