LoginSignup
31
31

More than 5 years have passed since last update.

gitのコミットメッセージのフォーマットを統一

Last updated at Posted at 2016-10-19

プロジェクト毎に「コミットメッセージのフォーマットを統一します」とドキュメントに書いてもなかなか統一されてなかったりして、管理者からするとちょっとストレスになったりしますよね。

gitにはちゃんと初期設定ファイルを作れば、毎回同じコミットメッセージのフォーマットを事前に用意してくれる仕組みがあるので使いましょう。

Sampleというリポジトリで進めます。

$ pwd
=> /path/to/Sample
$ git init
$ git config commit.template .gitmessage.txt
$ vim .gitmessage.txt
---例)以下のようなフォーマッットを指定
subject line

what happened

[ticket: X]
---

これだけです。 git config コマンドの結果は、 path/to/Sample/.git/config に書かれます。

あとは、 git commit を叩いてみてください。以下のようにエディタが開くようになります。

subject line

what happened

[ticket: X]
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
# modified:   lib/test.rb
#
~
~
".git/COMMIT_EDITMSG" 14L, 297C
31
31
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
31
31