Skip to content

Instantly share code, notes, and snippets.

@NxSoftware
Last active September 1, 2016 08:26
Show Gist options
  • Save NxSoftware/8e1265bb7542ad4e5a1f1ce074fba830 to your computer and use it in GitHub Desktop.
Save NxSoftware/8e1265bb7542ad4e5a1f1ce074fba830 to your computer and use it in GitHub Desktop.
git pre-commit hook to prevent committing files that contain a certain string
#!/bin/sh
git diff-index --name-status --cached HEAD -- | cut -c3- | while read FILE
do
if git diff --cached "$FILE" | grep -q "^+[^+].*// NOCOMMIT"; then
echo $FILE ' contains a NOCOMMIT string!'
exit 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment