Friday, May 24, 2013

How Git's Smudge And Clean Filters Work

The technique is powerful but obscure, so I created a repo on GitHub which demonstrates it.

Basically, smudge is equivalent to "run this code whenever you check anything out," and clean is equivalent to "run this code whenever you check anything in." One major caveat to that overgeneralization is that git expects the code you run to be a filter. Because of this, it not only expects input from standard out and passes your code input via standard in, it also suppresses both standard out and standard error.

(Like git-bisect, git filters allow you to execute arbitrary Unix software in a very powerful context, opening up the possibility for other use cases, but firmly encourages a particular use case.)