24

I'm trying to find all commits where a particular string or arbitrary capitalisation thereof (e.g. foobar ,FooBar, fooBar) was introduced/removed in a git repository.

Based on this SO answer (which covers a different basic use case), I first tried using git grep

git rev-list --all | xargs git grep -i foobar

This was pretty awful, as it only gave information as to whether the string is present in a commit, so I ended up with loads of superfluous commits.

I then tried pickaxe, which got me most of the way there, e.g.

git log --pickaxe-regex -S'foobar' --oneline

This only got the lowercase foobar. I tried the -i flag, but that doesn't seem to apply to the --pickaxe-regex option. I then resorted to using patterns like this, which got me a bit further:

git log --pickaxe-regex -S'.oo.ar' --oneline

Is there a way to make --pickaxe-regex do case-insensitive matching?

I'm using git v1.7.12.4.

zb226
  • 9,586
  • 6
  • 49
  • 79
Rob
  • 1,350
  • 12
  • 21
  • Just to be sure, try without the single quotes, and try with a more recent Git (preferably 2.0+). But keep in mind `-i` won't work with `'.oo.ar'` (regexp) before Git 2.0. – VonC Aug 19 '14 at 14:03

1 Answers1

32

The way the -i is used with pickaxe (see commit accccde, git 1.7.10, April 2012) is:

git log -S foobar -i --oneline

or

git log --regexp-ignore-case -Sfoobar

or

git log -i -Sfoobar

Note that with 1.x git versions this option will not work with a regexps, only with a fixed string. It works with regexps only since git 2.0 and commit 218c45a, git 2.0, May 2014.

BanksySan
  • 27,362
  • 33
  • 117
  • 216
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I'm probably still missing something here. I tried searching for a plain string using --pickaxe-regex, i.e. 'git log --pickaxe-regex -S foobar -i --online', and got 0 results. 'git log -i -S foobar --oneline' got me several hits. – Rob Aug 19 '14 at 14:09
  • 1
    @Rob you said options 2 and 3 were working. That would be `-Sfoobar`, not `-S foobar`. (no need for `--pickaxe-regex` if you are using the `-S`: I'll fix the answer) – VonC Aug 19 '14 at 14:10