【发布时间】:2014-05-21 07:49:11
【问题描述】:
我想用我的分支名称自动在我的提交消息前面加上方括号,例如:
[分行名称]进行了更改
这是我的 commit-msg 钩子:
#!/bin/sh
#
# Automatically adds branch name and branch description to every commit message.
#
BRANCH=$(git symbolic-ref HEAD | awk -F'/' '{print $3}')
if [ -n "$BRANCH" ]; then
echo ["$BRANCH"'] '$(cat "$1") > "$1"
fi
如果我使用 git commit -am "Commit message",这个钩子可以正常工作。但是如果我简单地使用 git commit 来使用完整的编辑器,我的提交消息会获得附加的 cmets,例如:
[TestHook] Test # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On
我从网络上的一个示例中复制了 commit-msg 脚本,并根据我的需要进行了一些修改。但是,我不是 bash 脚本专家,所以我怀疑我的脚本有问题。希望得到一些帮助!
谢谢!
【问题讨论】:
标签: git