Skip to content

Instantly share code, notes, and snippets.

@DiegoSalazar
Created June 15, 2016 17:18
Show Gist options
  • Save DiegoSalazar/0f4e81cb80c50128a890675b8d83bf4e to your computer and use it in GitHub Desktop.
Save DiegoSalazar/0f4e81cb80c50128a890675b8d83bf4e to your computer and use it in GitHub Desktop.
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
Copy link
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.

@cparker15
Copy link

Thank you so much for writing this!

Your Gist is ranked #1 for the Google search:

git pre-commit block string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment