I’m pretty prone to making stupid mistakes all the time. I think its a mixture of being busy, and being a natural scatter brain. In any case, mistakes happen, and thankfully over time developers have come up with a number of ways to combat mistakes. These usually take the shape in automated toolds. Unit tests are a great way to automated tool to help prevent stupid mistakes from happening, Git commit hooks are another. Git hooks are shell or other scripts that you install in your repo, and git will run them at certain points in time. One nice advantage of git commit hooks is you can install them locally and you can avoid publishing the stupid mistake you might make.
For me, I quite often commit
- if git-rev-parse --verify HEAD >/dev/null 2>&1; then
- for FILE in `git diff-index --check --name-status $against -- | cut -c3-` ; do
- # Check if the file contains 'debugger'
- if [ "grep 'debugger' $FILE" ]
- echo $FILE ' contains debugger!'
- exit 1
After creating the file its important to make it executable with
chmod +x .git/hooks/pre-commit or git won’t run your script. Git hooks are installed on a per-repo basis, which is kind of bad. Its also kind of good, in that you can easily install your own suite of git hooks and no-one will be the wiser. There are a number of hooks available in git, and you can learn all about them in Pro Git