# git log -S not finding all commits?

15 messages from 2009-10-08 to 2009-10-09. Participants: Daniel, Andreas Ericsson, Matthieu Moy, Nanako Shiraishi, Randal L. Schwartz, Scott Wiersdorf.
Thread: https://gitlist.dev/t/21155

## Daniel, 2009-10-08 08:21

Subject: git log -S not finding all commits?
Message-ID: <7ae12651.522df17b.4acda0f5.21a31@o2.pl>
URL: https://gitlist.dev/e/7ae12651.522df17b.4acda0f5.21a31%40o2.pl

```
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, 2009-10-08 09:12

Subject: Re: git log -S not finding all commits?
Message-ID: <4ACDACE6.9060509@op5.se>
URL: https://gitlist.dev/e/4ACDACE6.9060509%40op5.se
In-Reply-To: <7ae12651.522df17b.4acda0f5.21a31@o2.pl>

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

```

## Daniel, 2009-10-08 11:07

Subject: Re: git log -S not finding all commits?
Message-ID: <362436ca.6b5d0fc3.4acdc7e1.41b23@o2.pl>
URL: https://gitlist.dev/e/362436ca.6b5d0fc3.4acdc7e1.41b23%40o2.pl
In-Reply-To: <4ACDACE6.9060509@op5.se>

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

```

## Matthieu Moy, 2009-10-08 11:40

Subject: Re: git log -S not finding all commits?
Message-ID: <vpqbpkixgea.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqbpkixgea.fsf%40bauges.imag.fr
In-Reply-To: <362436ca.6b5d0fc3.4acdc7e1.41b23@o2.pl>

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

```

## Matthieu Moy, 2009-10-08 11:57

Subject: Re: git log -S not finding all commits?
Message-ID: <vpq63aqxflu.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpq63aqxflu.fsf%40bauges.imag.fr
In-Reply-To: <vpqbpkixgea.fsf@bauges.imag.fr>

```
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, 2009-10-08 12:49

Subject: Re: git log -S not finding all commits?
Message-ID: <49efcded.58cfa30b.4acddff5.4d773@o2.pl>
URL: https://gitlist.dev/e/49efcded.58cfa30b.4acddff5.4d773%40o2.pl
In-Reply-To: <vpq63aqxflu.fsf@bauges.imag.fr>

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

```

## Matthieu Moy, 2009-10-08 18:23

Subject: Re: git log -S not finding all commits?
Message-ID: <vpqiqepeocu.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqiqepeocu.fsf%40bauges.imag.fr
In-Reply-To: <49efcded.58cfa30b.4acddff5.4d773@o2.pl>

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

```

## Nanako Shiraishi, 2009-10-08 22:02

Subject: Re: git log -S not finding all commits?
Message-ID: <20091009070213.6117@nanako3.lavabit.com>
URL: https://gitlist.dev/e/20091009070213.6117%40nanako3.lavabit.com
In-Reply-To: <7ae12651.522df17b.4acda0f5.21a31@o2.pl>

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

```

## Randal L. Schwartz, 2009-10-08 22:52

Subject: Re: git log -S not finding all commits?
Message-ID: <86tyy9qz08.fsf@blue.stonehenge.com>
URL: https://gitlist.dev/e/86tyy9qz08.fsf%40blue.stonehenge.com
In-Reply-To: <vpq63aqxflu.fsf@bauges.imag.fr>

```
>>>>> "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, 2009-10-09 08:55

Subject: Re: git log -S not finding all commits?
Message-ID: <vpq1vldx7xx.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpq1vldx7xx.fsf%40bauges.imag.fr
In-Reply-To: <86tyy9qz08.fsf@blue.stonehenge.com>

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

```

## Scott Wiersdorf, 2009-10-09 12:41

Subject: Re: git log -S not finding all commits?
Message-ID: <20091009124149.GA50560@perlcode.org>
URL: https://gitlist.dev/e/20091009124149.GA50560%40perlcode.org
In-Reply-To: <vpq1vldx7xx.fsf@bauges.imag.fr>

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

```

## Randal L. Schwartz, 2009-10-09 14:07

Subject: Re: git log -S not finding all commits?
Message-ID: <864oq8r795.fsf@blue.stonehenge.com>
URL: https://gitlist.dev/e/864oq8r795.fsf%40blue.stonehenge.com
In-Reply-To: <vpq1vldx7xx.fsf@bauges.imag.fr>

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

```

## Matthieu Moy, 2009-10-09 14:26

Subject: Re: git log -S not finding all commits?
Message-ID: <vpq4oq8prse.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpq4oq8prse.fsf%40bauges.imag.fr
In-Reply-To: <864oq8r795.fsf@blue.stonehenge.com>

```
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, 2009-10-09 14:28

Subject: Re: git log -S not finding all commits?
Message-ID: <86vdioprpf.fsf@blue.stonehenge.com>
URL: https://gitlist.dev/e/86vdioprpf.fsf%40blue.stonehenge.com
In-Reply-To: <vpq4oq8prse.fsf@bauges.imag.fr>

```
>>>>> "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, 2009-10-09 14:33

Subject: Re: git log -S not finding all commits?
Message-ID: <20091009143341.GA50862@perlcode.org>
URL: https://gitlist.dev/e/20091009143341.GA50862%40perlcode.org
In-Reply-To: <864oq8r795.fsf@blue.stonehenge.com>

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

```
