Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
git pre-commit hook to block changes containing the string debug in a ruby comment
#!/bin/sh
. git-sh-setup # for die
git-diff-index -p -M --cached HEAD -- | grep '^+' | grep -n '# debug' && die 'Blocking commit: debug detected in code'
:
@DiegoSalazar

This comment has been minimized.

Copy link
Owner Author

DiegoSalazar commented Jun 15, 2016

Copy this file into your repo's .git/hooks directory and make it executable. When any change to your code is added that contains the string # debug it will block the commit from happening.

cd /path/to/your/repo/.git/hooks
wget https://gist.githubusercontent.com/DiegoSalazar/0f4e81cb80c50128a890675b8d83bf4e/raw/c81f7f3fe2f232eba480c29ab3c3c87018a1d9f9/pre-commit
sudo chmod +x pre-commit

Useful when leaving the snippet binding.pry # debug in your code during debugging sessions, and other things you don't want to accidentally put in master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.