Skip to content

Instantly share code, notes, and snippets.

@kyanro
Created March 27, 2013 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyanro/5254422 to your computer and use it in GitHub Desktop.
Save kyanro/5254422 to your computer and use it in GitHub Desktop.
windows版 SourceTreeのコミットログに自動でブランチ名とかチケット番号を入れる方法 ref: http://qiita.com/items/d7a0f01236f90339516a
#!/bin/sh
#ブランチ名を取得 もっといい方法あるかも。
Branch="$(git branch | grep "*" | awk '{print $2}')"
if [ $Branch == "master" ] ; then
#masterでのコミットは別ルールにしたかったのでとりあえず分けてみた
ReqestNo=""
CommitBranch="master"
else
#正規表現でブランチ名からとチケット番号と、コミット番号抜きのブランチ名を取得
ReqestNo="$(echo $Branch | sed -e "s/^.*-\([0-9]\+\)$/\1/g")"
CommitBranch="$(echo $Branch | sed -e "s/^\(.*\)-[0-9]\+$/\1/g")"
fi
#コミットメッセージの最初にチケット番号を、最後にコミット番号抜きのブランチ名を追加
mv $1 $1.tmpbycommit-msg
echo -n "[#$ReqestNo] " > $1
cat $1.tmpbycommit-msg >> $1
echo "*$CommitBranch" >> $1
@kyanro
Copy link
Author

kyanro commented Mar 27, 2013

.git/hooks/commit-msg

example)
branch name hotfix-9999

add commit message [#9999] and *hotfix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment