LoginSignup
1
0

More than 1 year has passed since last update.

【Git】コミットメッセージのテンプレートを設定する方法

Posted at

テンプレートのファイルを作成

ファイルを作成しテンプレートを記述します。

ファイル名やパスはどのようなものでも大丈夫です。

今回は~/.gitmessage.txtを作成します。

touch ~/.gitmessage.txt

~/.gitmessage.txt以下のように記述します。

subject line

what happened

[ticket: X]

Gitの設定を変更する

テンプレートファイルを作成したら以下のコマンドを実行してGitの設定を変更します。

git config --global commit.template ~/.gitmessage.txt

上記を実行すると~/.gitconfigまたは~/.config/git/configに以下が追記されます。

[commit]
  template = /Users/user_name/.gitmessage.txt

なおリポジトリごとに設定する場合には以下のコマンドを実行します。

git config --local commit.template ~/.gitmessage.txt

git commitする

上記の設定をしてからgit commitすると以下のように~/.gitmessage.txtの記述が
.git/COMMIT_EDITMSGに表示されます。

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 main
# Changes to be committed:
#	modified:   sample/sample.txt

1
0
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
1
0