基于这个问题,我做了一个 git hookprepare-commit-msg
#!/bin/sh
#
# Automatically adds branch name and branch description to every commit message.
#
NAME=$(git branch | grep '*' | sed 's/* //')
DESCRIPTION=$(git config branch."$NAME".description)
echo "[$NAME]"': '$(cat "$1") > "$1"
if [ -n "$DESCRIPTION" ]
then
echo "" >> "$1"
echo $DESCRIPTION >> "$1"
fi
它适用于简单的提交。示例 -[issue14020]: some text message
如果在 issue14020 分支中提交。
但后来我做了一个变基,我收到了这样的消息[(no branch)]: [issue14020]: some text message
。有没有办法跳过这个“无分支”部分?