copy pre-commit
into the repo's .git/hooks/
folder, then try committing a file that has the string DO_NOT_COMMIT_THIS
in it.
Created
March 11, 2019 23:57
-
-
Save r-k-b/173a0951cf49ee5e26795f86985db24a to your computer and use it in GitHub Desktop.
Prevent accidental commits of files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh -e | |
disallowed="DO_NOT_COMMIT_THIS" | |
git diff --cached --name-status | while read x file; do | |
if [ "$x" == 'D' ]; then continue; fi | |
for word in $disallowed | |
do | |
if egrep $word $file ; then | |
echo "ERROR: Disallowed expression \"${word}\" in file: ${file}" | |
exit 1 | |
fi | |
done | |
done || exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment