参考 https://codingluka.com/git-precommit-hooks-copy/
但是因为其内的pre-commit脚本链接失效了
就手动复制替换成如下代码
pre-commit
.git/hooks/pre-commit文件:
FILES_PATTERN='\.(rb|haml|coffee)(\..+)?$'
FORBIDDEN='binding.pry'
git diff --cached --name-only | \
grep -E $FILES_PATTERN | \
GREP_COLOR='4;5;37;41' xargs grep --color --with-filename -n $FORBIDDEN && \
echo 'COMMIT REJECTED' && \
exit 1
exit 0
如果你提交的文件不含FILES_PATTERN内后缀的文件会直接报COMMIT REJECT 为此你需要将相应的文件后缀加入FILES_PATTERN 比如 erb js css**