Skip to content

Instantly share code, notes, and snippets.

@omribahumi
Created February 24, 2013 13:26
Show Gist options
  • Save omribahumi/5023839 to your computer and use it in GitHub Desktop.
Save omribahumi/5023839 to your computer and use it in GitHub Desktop.
pre-commit git hook to make sure developers don't accidentally commit code they didn't mean to commit :)
#!/bin/sh
# pre-commit git hook to make sure developers don't accidentally commit code they didn't mean to commit :)
REMOVEME_STRING="REMOVEME"
ALLOW_COMMITTING_REMOVEME=`git config hooks.allowcommittingremoveme`
# redirect stdout to stderr
exec 1>&2
if [ "$ALLOW_COMMITTING_REMOVEME" != "true" ] &&
[ "$(git diff --cached | egrep '^\+[^\+]+' | grep $REMOVEME_STRING)" != "" ]
then
echo "Error: Attempt to add a line containing the forbidden string $REMOVEME_STRING"
echo
echo "If you know what you are doing you can disable this check using:"
echo
echo " git config hooks.allowcommittingremoveme true"
echo
echo "After you're done, set it back using:"
echo
echo " git config --unset hooks.allowcommittingremoveme"
exit 1
fi
@amirnissim
Copy link

This is awesome! can you make it unstage hunks surrounded with NOCOMMIT? something like:

// NOCOMMIT
[some code]
// /NOCOMMIT

[some code] will not be commited.

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