2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

gitのコミットメッセージにissue番号を自動付与する

Last updated at Posted at 2023-01-05

概要

GitHubではコミットメッセージにissue番号が入っていると、コミットメッセージがissueにも表示されるようになる。

開発を続けていくとコード上の変更がなぜ行われたかがわからなくなることがある。
その際にコミットメッセージだけではなく、元issueも参照できると変更理由やそれに伴うレビュー内容が追跡しやすくなる。
そのため、コミットメッセージにissue番号を自動付与する仕組みを導入する。

前提条件

ブランチ名は issue-【issue番号】-【任意の文字列】とする。
(実際は-【番号】-だけで抜き出せたりもするが一応そんなルールに
例:
 issue-15-add-aspell
 issue-18-

導入方法

該当プロジェクトの.git\hooks\commit-msgを以下の通りとする

.git\hooks\commit-msg
#!/bin/sh

#ブランチ名を取得
Branch="$(git branch --show-current)"

#正規表現でブランチ名からissue番号を取得
RequestNo="$(echo $Branch | sed -e "s/.*\-\([0-9]*\)\-.*/\1/g")"

#コミットメッセージの最初にチケット番号を追加する
mv $1 $1.tmpbycommit-msg
echo -n "#$RequestNo " > $1
cat $1.tmpbycommit-msg >> $1

こんな感じ

GitHub上でcodeをblameで見ると…
Screenshot_190.png
となっているので、どのissueで対応したブランチなのかがすぐわかる

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?