问题
I have a git hook for commit-msg which works quite happily when I run
git commit -m "MSG HERE"
but if I run
git commit -a
Which triggers committing using your text editor it skips the hook.
Any suggestions on how to fix this?
My hook is as follows
#!/bin/bash
if ! egrep -q 'DAVE-[0-9]+' $1 ; then
echo "No Jira Issue Number found" >&2
exit 1
fi
if [[ "$(wc -c $1 | awk '{print $1}')" -le 20 ]] ; then
echo "Commit message too short" >&2
exit 1
fi
回答1:
I can't reproduce your problem, so my guess here is that there's a misunderstanding -- the commit-msg
hook runs after you specified your message, ie. after you close the commit text editor, not before, so you will only notice the changes in your git log
.
EDIT:
Are you sure you're not counting comment lines? These would easily blow up the message to above 20 characters. Use something like cat $1|grep -vE '^#'|wc -c|awk ...
.
来源:https://stackoverflow.com/questions/27983784/git-commit-a-bypasses-git-hook-when-it-shouldnt