A lot of times when I’m programming, I need to write a few lines of code that test what I’m working on. This can be a top-level function call, a few log entries, etc. Much to my dismay, I tended to end up with this debug code committed to git.
I decided I wasn’t going to take it anymore.
Git’s pre-commit hook to the rescue
Now, whenever I add one of these lines, I mark it with a special comment:
Then in my pre-commit hook, I symlink a script that checks for
DEBUGcomments in various languages for that repo:
Using this, trying to commit any code that has DEBUG comments will fail with the output:
Please address the DEBUG comments in following files before committing: user.js
This forces going back in and cleaning up your code before committing it. Wicked.
Get it yourself
Grab the pre-commit hook off my Github to END THE SUFFERING and stop committing your debug code.