Including the current branch name in the commit template

后端 未结 3 1452
轻奢々
轻奢々 2020-12-05 14:31

I have a commit template set up for git, and I would like to include the name of the current branch in it. I usually set up the branch to be the bug id, and it would help me

3条回答
  •  渐次进展
    2020-12-05 14:43

    Just cobbling together the comments from Jefromi's answer, I end up with something like this. Surely it could be tighter (if I knew what I was doing):

    tempFile='/tmp/git-commit-template'
    git config commit.template "$tempFile"
    rm $tempFile
    branch=$(git symbolic-ref HEAD|sed s#refs/heads/##) exec 3<> "$tempFile" && awk -v TEXT="[$branch]" 'BEGIN {print TEXT}{print}' "$tempFile" >&3
    git add .
    git commit -a
    

提交回复
热议问题