Search your logs in git with the magic of the git pickaxe...

If, for example, we want to find out when the ZLIBBUFMAX constant was originally introduced, we can use the -S option (colloquially referred to as the Git โ€œpickaxeโ€ option) to tell Git to show us only those commits that changed the number of occurrences of that string.

$ git log -S ZLIB_BUF_MAX --oneline
e01503b zlib: allow feeding more than 4GB in one go
ef49a7a zlib: zlib can only process 4GB at a time

This from SO is potentially a better description:

If you want to find all commits where commit message contains given word, use

$ git log --grep=word

If you want to find all commits where "word" was added or removed in the file contents (to be more exact: where number of occurences of "word" changed), i.e. search the commit contents, use so called 'pickaxe' search with

$ git log -Sword

In modern git there is also

$ git log -Gword

to look for differences whose added or removed line matches "word" (also commit contents).

Note that -G by default accepts a regex, while -S accepts a string, but can be modified to accept regexes using the --pickaxe-regex.

I'm kinda surprised by the lack of space in -Sword. The git docs have a space: git log -S ZLIB_BUF_MAX --oneline. Do those return the same thing, or is git log -S word searching for ฦƒword? Guess there are ways to find out...

Labels: ,