Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A git pre-commit hook example.
# This pre-commit hook checks that you havn't left and DONOTCOMMIT tokens in
# your code when you go to commit.
# To use this script copy it to .git/hooks/pre-commit and make it executable.
# This is provided just as an example of how to use a pre-commit hook to
# catch nasties in your code.
# Work out what to diff against, really HEAD will work for any established repository.
if git rev-parse --verify HEAD >/dev/null 2>&1
# Initial commit: diff against an empty tree object
diffstr=`git diff --cached $against | grep -e '^\+.*DONOTCOMMIT.*$'`
if [[ -n "$diffstr" ]] ; then
echo "You have left DONOCOMMIT in your changes, you can't commit until it has been removed."
exit 1

This comment has been minimized.

Show comment Hide comment

wkoszycki Oct 19, 2016

Cool ! :-)

Cool ! :-)

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