开发者

Automating git commit message per branch

I keep finding myself forgetting to add refs #ticket to my commits. It's a pain. I usually use at least one branch per ticket, or at least, there might be mutliple branches for one ticket, but usuall开发者_如何学Goy not the other way around.

So I was thinking of something like add a branch.ticket config option and then retrieving it from probably prepare-commit-msg and prepending "refs #" to my message.

Maybe after this is done, even adding a hook or an alias to ask for a #ticket when I create a new branch.

Can someone help me build these? I'm fairly new at git, and am no bash guru either, but I can figure it out if pointed in the right direction.

By now, I gather I have to call

git config --add branch.<branchname>.ticket <ticketnumber>

and then do something like

prepend `git config branch<branchname>.ticket` $file

basically. I think. Anyone can confirm this? and tell me how to get < branchname >?


This sounds good. You can get the current branch name (if there is one) with git symbolic-ref HEAD.

You might want to cut off the /refs/heads/. I'm using this in my prompt script:

local branchname=$(timeout 1s git symbolic-ref HEAD 2> /dev/null | cut -b 12-)

and then a check on being the empty string.


You are on right track I believe

There are many ways to get the current branch:

git branch | grep '^*' |sed s/\*\ //

Or use git symbolic-ref HEAD and get the last part after /

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜