Bruno Buccolo

The patches/ folder

Do you know those bits of code we write to debug something? Sometimes we can make them part of the codebase, by hiding them using debug log levels, or behind ENV checks.

However, sometimes the code is so nasty interesting, that it cannot be part of the codebase.

I have a solution for you – the patches/ folder!

Add it to your global Git ignore:

echo "patches/" >> ~/.gitignore

Now on your favorite project, you can create the new folder:

cd project/
mkdir patches/

So let’s say you’re writing the debug code again. It got the job done, but let’s save it for the next time you’re debugging the same area of code:

git diff > patches/my-patch.diff
git reset --hard

Nice. It’s beautifully saved under patches/.

Now, let’s see how to apply it:

git apply patches/my-patch.diff

Every project I work on ends up having multiple debugging bits of code. I find saving those patches to be handier than a debug branch in git or doing git stash or even notes.

Enjoy 🚢

PS: If you want a more complete solution to patch management, give Stacked Git a try.

© 2011– Bruno Buccolo (@buccolo) | Made in São Paulo ☂