The git pickaxe

I often see people using git’s blame command, which they use for checking who made a certain change in a certain file tracked by git. And usage of blame is said to be a reason for not fixing code formatting issues on a larger scale. Reason being is that blame will show the commit fixing the formatting of the line, and not the “real” last time the line was touched. And because blame only shows the last commit and person that touched a line, I regularly have people asking me about some logic they don’t agree with even though I am not the person who actually modified it. Let alone add it.

All these issues would be fixed if people wouldn’t use git’s blame command for this, but instead the git pickaxe. Pickaxe is the “-S” argument of git log and filters the output of git log by only commits that added and/or removed a line containing a certain value. So basically a search not of the commit message, but commit contents.

Here’s an example:

$ g log -S 'return base64.RawURLEncoding.EncodeToString(b), nil'
commit 38999c54e1f0e3aebc812f5a56e41c9d60936558
Author: Erik <erikj@redacted>
Date:   Tue Oct 10 10:40:52 2017 +0100

    Generate new devices for each new /login (#281)

commit 50aacd4f3c0225e78bd3be773b29bbbdcc48072e
Author: Kegsay <kegsay@redacted>
Date:   Tue May 30 17:51:40 2017 +0100

    Hook up registration/login APIs and implement access token
	generation (#122)

The pickaxe can of course also be combined with other log filters. For instance, filtering by directory or file:

$ g log -S 'return base64.RawURLEncoding.EncodeToString(b), nil' clientapi/auth

“-p” is also quite useful when working with the pickaxe because it will also show the commit diff instead of just the metadata.

Using the pickaxe instead of blame also adhires to the saying that “git tracks content not files”.