问题
i have git commit hook script , whom checking commit input message, and if message not contain the word "updated" the script has reject commit.
#!/bin/bash
read -p "Enter a commit message: " message
if [[ ${message} != *"updated"* ]];then
echo "Your commit message must contain the word 'updated'"
else
git commit -m "$message"
fi
how to make this hook automatically executable if i try to push some files in my local repo with message: git commit -m "updated:something" , my idea is make it not like "run this script to do commit" , but then you open console and trying to make a commit by typing commant , script will check your commit message automatically and pass it or reject.
回答1:
Taking commit-msg
for example.
#!/bin/bash
MSG="$1"
if ! grep -qE "updated" "$MSG";then
cat "$MSG"
echo "Your commit message must contain the word 'updated'"
exit 1
fi
chmod 755 commit-msg
and copy it as .git/hooks/commit-msg
.
来源:https://stackoverflow.com/questions/45416049/git-pre-commit-hook-check-message