git实现提交前自动替换某些字符串

新建hook文件

# cat .git/hooks/pre-commit

##!/bin/sh
for FILE in `git diff --cached --name-only --diff-filter=ACM`;do
    echo $FILE
    sed -i '' -E 's/(key1|key2)/coder4/' $FILE 
    git add $FILE
done

添加执行权限

chmod a+x .git/hooks/pre-commit

之后,在commit后,会自动替换字符串

 

Leave a Reply

Your email address will not be published. Required fields are marked *