TECHSTEP

ITインフラ関連の記事を公開してます。

GitLab Commit message templateを使ってみる

今回はGitLabのCommit message templateを紹介します。

docs.gitlab.com

背景

Commit message templateは、名称の通りコミット時に利用するテンプレートです。GitLabではMerge commit message / Squash commit messageの2種類のテンプレートが用意されています。

Commit message templateはいくつかの変数が提供されています。

  • %{source_branch}: コミット元の、マージされるブランチ名
  • %{target_branch}: コミット先のブランチ名
  • %{title}: Merge requestのタイトル
  • %{issues}: MRで言及、クローズしたIssue
  • %{reference}: Merge requestへのリファレンス

docs.gitlab.com

それぞれのデフォルトのテンプレートは以下の通りです。

Merge commit message template

Merge branch '%{source_branch}' into '%{target_branch}'

%{title}

%{issues}

See merge request %{reference}

Squash commit message template

%{title}

デフォルトのテンプレートの状態でMerge commitを作成すると、以下のように表示されます。

試しにMerge commit message templateを修正してみます。修正は 設定マージリクエスト 画面から可能です。

修正後にMerge commitを作成すると、以下のようにメッセージが変更されるのを確認できます。