1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

feature/xxx というブランチでコミットする時コミットメッセージの頭に必ず xxx: が入るようにした

Last updated at Posted at 2018-03-28

これ何

タイトルの通りのことを git alias で実現した。
要は現在のブランチがfeature/SOMEBTS-10000な時、コミットメッセージの頭に必ずSOMEBTS-10000: が入ってくれるようにした。
まあ xxx がチケット番号であること前提な感じはある。

.gitconfig
[alias]
  coam = "!fetch(){ p=`git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \\(.*\\)/\\1/' -e '/^feature\\//!d' -e 's/^feature\\/\\(.*\\)/\\1: /'`; git commit -am \"$p$1\" ${@:2}; };fetch"
result
hokkun:gittest [feature/SOMEBTS-12345]$ touch yyy
hokkun:gittest [feature/SOMEBTS-12345]$ git add yyy
hokkun:gittest [feature/SOMEBTS-12345]$ git coam "Super commit"
[feature/SOMEBTS-12345 ff752e6] SOMEBTS-12345: Super commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 yyy

1ミリ位シェル芸芸人に近づいた感じがある。

ちなみに普段からプロンプトにはブランチを表示している。その方法についてはこちらの Qiita 記事が詳しい。

ハマったところ

sed で使っているバックスラッシュを二重エスケープする必要があった。これでしばらくハマった。config にそもそもエラーが入ってると GIT_TRACE=1とかそもそも効かないのでデバッグがしんどかった。

ちなみに

feature/ で始まらないときはちゃんと何も入らない。

後で直しました

--amend などの option も受け入れる。ただし message の後のみ。

1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?