12
12

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.

[memo]gitのコミットで自動でissue番号をメッセージに入れてくれる様にする。

Last updated at Posted at 2016-03-31

コミットの度にブランチ名のissue確認して入れるのは入れ忘れもするし、面倒なので、(色んなパターン用意するのは面倒なので)簡易的なものを作成したので、メモ。

ブランチ名のルール

ブランチ名のどこにissue番号を入れてもいいけど、ブランチ名に数字はissue番号のみ

git hooksの修正

.git/hooks/prepare-commit-msg
#!/bin/bash

PREFIX=${PREFIX:-#}

message_file=$1
mode=$2

if [ "$mode" = "" ] || [ "$mode" = "message" ] ; then
  ticket_number=`git branch | grep "*" | awk '{print $2}' | sed -e 's/[^0-9]//g' `
  if [ "$ticket_number" != "" ]; then
    mv $message_file $message_file.tmp
    echo "$PREFIX$ticket_number `cat $message_file.tmp`" > $message_file
  fi
fi

$ chmod +x prepare-commit-msg

編集履歴

2017/09/30 : issue番号とコメントの間に改行が入ってしまうので、繋げるだけにしました。

12
12
0

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
12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?