Skip to content

Instantly share code, notes, and snippets.

@jhbabon
Created March 6, 2012 09:55
Show Gist options
  • Save jhbabon/1985403 to your computer and use it in GitHub Desktop.
Save jhbabon/1985403 to your computer and use it in GitHub Desktop.
Pre commit git-hook that checks if there are changes that must not be committed. The changes should be marked with a NOCOMMIT flag.
#!/bin/sh
#
# Do not commit files with the flag: NOCOMMIT
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
if test "$(git diff --cached $against | grep 'NOCOMMIT')"
then
echo "ERROR: Attempt to commit not desired changes"
echo
echo "The changes are marked as NOCOMMIT. Use this flag to check"
echo "when a change should not be committed"
echo
exit 1
fi
# exec git diff-index --check --cached $against --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment