我想用prepare-commit-msg鉤子。我使用的功能和bug修正分支(功能/ ISSUEKEY-23123-一些特徵),我想前面加上ISSUEKEY-23123到commit消息:git - 用部分分支名稱擴展commit hook
#!/bin/bash
BRANCH_NAME=$(git branch | grep '*' | sed 's/* //')
STR=`echo $BRANCH_NAME | grep -E 'ISSUEKEY-[0-9]*' -o`
if [[ $BRANCH_NAME == *"feature"* ]] || [[ $BRANCH_NAME == *"bugfix"* ]]
then
echo $STR > $1
fi
這工作,但它摒棄了標準的消息v正顯示出我要提交,如:
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# Explicit paths specified without -i or -o; assuming --only paths...
# On branch feature/ISSUEKEY-1716-model-implement
# Your branch is based on 'origin/feature/ISSUEKEY-1716-model-implement', but the upstream is gone.
# (use "git branch --unset-upstream" to fixup)
#
# Changes to be committed:
# new file: asd
#
# Untracked files:
# FSTD-1716
# TMP
#
有沒有辦法要麼預先考慮STR
到輸出,或撥打一個git命令什麼打印我所提到的標準提交信息?
打開的提交信息應該是:
ISSUEKEY-1716
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# Explicit paths specified without -i or -o; assuming --only paths...
# On branch feature/ISSUEKEY-1716-model-implement
# Your branch is based on 'origin/feature/ISSUEKEY-1716-model-implement', but the upstream is gone.
# (use "git branch --unset-upstream" to fixup)
#
# Changes to be committed:
# new file: asd
#
# Untracked files:
# FSTD-1716
# TMP
#