あらゆる種類の問題/チケット番号付けコミットメッセージの完全な解決策は次のとおりです。
prepare-commit-msg
#!/bin/bash
# Append issue number / bug tracking URL to commit.
#
# If the branch name contains the issue number, it will append it to the
# commit message. Example:
#
# BRANCH NAME LINE TO APPEND
# feature/GH-123-emoji GitHub: #123
# WRIKE-123-add-payment Wrike: https://www.wrike.com/open.htm?id=123
# UNKNOWN-123 Issue: #123
branchName=`git rev-parse --abbrev-ref HEAD`
IFS=- read issueTracker issueNumber <<< $(echo $branchName | sed -nr 's,([a-z-]+/)?([A-Z]+-[0-9]+)-.+,\2,p')
if [[ -z $issueNumber ]]; then
exit 0
fi
case "$issueTracker" in
WRIKE)
line="Wrike: https://www.wrike.com/open.htm?id=$issueNumber"
;;
GH)
line="GitHub: #$issueNumber"
;;
GL)
line="GitLab: #$issueNumber"
;;
*)
line="Issue: #$issueNumber"
;;
esac
# If the commit message already contains the line (`--amend`), then do
# not add it again.
if ! ( grep "$line" "$1" > /dev/null ); then
sed -i.bak -e "/# Please enter the commit message for your changes./ s,^,$line\n\n," $1
fi
リポジトリのディレクトリに配置してリポジトリにのみ適用するか、 core.hooksPathを.git/hooks
設定してそのディレクトリにコピーし、すべてのリポジトリに適用します。~/.gitconfig
他の便利なスクリプトに加えて、私の設定ファイルリポジトリを参照してください。