LoginSignup
18
16

More than 5 years have passed since last update.

Git の Commit Template + Subliem Text 2 の Snippet でコミットメッセージの作法を統一・効率化する #git

Last updated at Posted at 2015-01-28

:musical_score: 概要

Git の Commit Template でコミットメッセージの作法を統一し、
Subliem Text 2 の Snippet でコミットメッセージの作法にのっとった入力を効率化します

:raised_hand: 前提

  • チーム全員が Sublime Text 2 を利用しています
  • 以下のように、 git の core.editor を設定しておきます
# Windows 環境を利用しています
$ git config --global core.editor "'c:/program files/sublime text 2/sublime_text.exe' -w"

目的

  • コミットメッセージの作法統一
    • 作法の統一を手動に頼らない
      • Snippet で最小の手間で正確に入力
    • 脳の記憶域に頼らない
      • Commit Template のコメントに Snippet のヘルプを表示しておくことで Snippet のキーワードを忘れても安心
    • 1 キーでも楽に入力する
      • 1 行目にコミット要約を入力後、ファイル末尾に移動すれば少ないキー入力でコミット詳細を入力可能

:ballot_box_with_check: デフォルトの挙動を確認

git commit をオプション指定なしで呼び出した場合、
以下のようなテンプレートとともにエディタが起動します。

任意のメッセージを入力・保存し、テキストを閉じるとコミットメッセージが登録されます。


# 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:   hoge.txt
#

Snippet 作成

Atom Editor の Git Commit Messages
Consider starting the commit message with an applicable emoji: のように、

絵文字からコミット要約(コミットの1行目のメッセージ)を始めるとものとします。
この際に利用する Sublime Text の Snippet を作成します。

  • Add カテゴリの Snippet 例
cm_add.sublime-snippet
<snippet>
  <content><![CDATA[
:new: Add: ${1:summary}
]]></content>
  <tabTrigger>cm_add</tabTrigger>
  <scope>text.plain</scope>
  <description>git commit 時の 1行目 メッセージテンプレート(カテゴリ:追加)</description>
</snippet>

その他、一通りの Snippet は下記に公開してあります。
Git Commit first line commit templates

上記の Snippet を各開発の Sublime Text2 に追加します。

設定

:skull: commit.template を作成

.commit.template

# ↑↑↑ コミット要約を 1行 50 字以内で記述してください ↑↑↑
# 下記の Snippet を利用できます。
# 新規追加 / cm_add
# :new: Add: input_your_summary
# バグ修正 / cm_bug
#:bug: Fix: input_your_summary
# 機能変更 / cm_modify
#:hammer: Modify: input_your_summary
# リファクタリング / cm_refactor
#:recycle: Refactor: input_your_summary
# 自動生成や自動編集されたファイル / cm_tool
#:computer: Tool: input_your_summary
# 削除 / cm_delete
#:x: Remove: input_your_summary

# ↓↓↓ コミット詳細を最後の行以降に記述してください ↓↓↓

作成したファイルを git に設定

git config --global commit.template $HOME/.commit.template

# 個別のプロジェクトに設定する場合は、 --global は不要
# git config commit.template ./.commit.template

実演

demo1.gif

BitBucket で Emoji 付きコミットメッセージを確認

bitbucket.png

:pencil: メモ

Emoji などを含めたコミットルール自体の是非については、論点ではないのでスルーをお願いします。

18
16
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
18
16