新建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
# 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
# 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
chmod a+x .git/hooks/pre-commit
chmod a+x .git/hooks/pre-commit
之后,在commit后,会自动替换字符串