Parse branch name, initiate commit with name in the commit message

后端 未结 1 1486
别跟我提以往
别跟我提以往 2020-12-07 06:00

My team uses a common naming convention for branch names, which include the Jira task number in the branch name.

feature/ACD-1664_update-api-c

相关标签:
1条回答
  • 2020-12-07 06:07

    Although this is not the solution you requested, I'd like to hint at another way to cover this, with a commit hook :

    You can put in .git/hooks a commit-msg file with these contents :

    #!/bin/bash
    current_branch="$(git rev-parse --abbrev-ref HEAD)"
    tmp=$(mktemp) || exit
    echo "$current_branch $(cat "$1")" > "$tmp"
    mv "$tmp" "$1"
    

    (Thanks guys for the improvements in bash syntax made with your help here)

    Then it would automatically prepend your commit messages with the branch name, which does the trick in JIRA.

    For the rare occasions when you'd prefer NOT to trigger the hook, do this :

    git commit -n -m"Your message"
    
    0 讨论(0)
提交回复
热议问题