LoginSignup
6
4

More than 5 years have passed since last update.

IntelliJ IDEA PluginのGit Commit Templateについて

Posted at

概要

トレンド入り(2018/01/31現在)している”【今日からできる】コミットメッセージに 「プレフィックス」 をつけるだけで、開発効率が上がった話”という記事に感銘を受けて、普段使っているIntelliJ IDEAに便利なプラグインがないかと探したところ、Git Commit Templateというプラグインがありましたので使ってみました。

環境

  • Windows 10 Professional
  • IntelliJ IDEA 2017.3
    • Git Commit Template plugin 1.0.0

参考

使い方

プラグインをインストールするとコミット画面にアイコンが追加されています。

g0.png

アイコンをクリックするとコミットメッセージを入力するダイアログが表示されます。

g1.png

OKボタンをクリックすると入力内容がコミットメッセージ欄へ反映されます。

g2.png

選択リストのType of change以外の入力はオプションです。

g3.png

上図のようにBreaking changesClosed issuesまで入力すると反映されるコミットメッセージは次のようになります。

docs(README.md): Add comment to README.md

I added a description of unit test code that uses temporary files.

BREAKING CHANGE: Breaking changesについての説明

Closes クローズするissuesの番号

Type of change

このプラグインではTypeに以下の項目から選択します。

  • feat - Features
  • fix - Bug Fixes
  • docs - Documentation
  • style - Styles
  • refactor - Code Refactoring
  • perf - Performance Improvements
  • test - Tests
  • build - Builds
  • ci - Continuous Integrations
  • chore - Chores
  • revert - Reverts

参考までに、他のプロジェクトではどのようなスタイルをとっているのか調査してみました。

jQuery の場合

jQueryはprefixにTypeを使用するスタイルではなく、代わりにComponentという情報を使っていました。

Commit Guidelines
Subject
This is the first line. It consists of a component, like "Event" or "Autocomplete". This line must be 72 characters or less. There should be no full stop (period) at the end.

 Component: Short Description

 Optional Long Description

 Fixes #xxx
 Closes gh-yyy
 Ref #zzz

The Go Programming Language の場合

Goは、パッケージ名をprefixに使用しているようです。

The first line of the change description is conventionally a one-line summary of the change, prefixed by the primary affected package, and is used as the subject for code review email.

math: improve Sin, Cos and Tan precision for very large arguments

The existing implementation has poor numerical properties for
large arguments, so use the McGillicutty algorithm to improve
accuracy above 1e10.

The algorithm is described at http://wikipedia.org/wiki/McGillicutty_Algorithm

Fixes #159

NumPy (Pythonの拡張モジュール) の場合

NumPyは、Standard acronymsという記号をprefixに使用しているようです。
ただしprefixを付けることは必須ではなく任意のようです。実際に直近のコミットログを見るとprefixのついていないコミットがありました。

Describing the motivation for a change, the nature of a bug for bug fixes or some details on what an enhancement does are also good to include in a commit message. Messages should be understandable without looking at the code changes. A commit message like MAINT: fixed another one is an example of what not to do; the reader has to go look for context elsewhere.

ENH: add functionality X to numpy.<submodule>.

The first line of the commit message starts with a capitalized acronym
(options listed below) indicating what type of commit this is.  Then a blank
line, then more text if needed.  Lines shouldn't be longer than 72
characters.  If the commit is related to a ticket, indicate that with
"See #3456", "See ticket 3456", "Closes #3456" or similar.

下記に、この記号の種類の一部を抜粋します。

  • BUG - bug fix
  • DOC - documentation
  • ENH - enhancement
  • MAINT - maintenance commit (refactoring, typos, etc.)

Scope of this change

この欄の入力はオプションです。スコープとして入力する情報は、組織やプロジェクトによって異なることが多いと思うので、選択式ではなく自由入力となっているようです。

ただし、空欄のままでコミットメッセージへ反映させると、たとえば下記のようにカラの括弧が出力されてしまいます。

docs(): Add comment to README.md

参考として、スコープにどのような情報を入力しているのか調査したところ、下記の2つのプロジェクトの事例を見つけましたので引用します。
(コミットメッセージにスコープを入力するという事例がなかなか見つけられず、Typeに比べると一般的ではないようです。)

AngularJS の場合

Scope could be anything specifying place of the commit change. For example $location, $browser, $compile, $rootScope, ngHref, ngClick, ngView, etc...

You can use * when the change affects more than a single scope.

karma-runner/karma の場合

  • init
  • runner
  • watcher
  • config
  • web-server
  • proxy
  • etc.

The can be empty (e.g. if the change is a global or difficult to assign to a single component), in which case the parentheses are omitted. In smaller projects such as Karma plugins, the is empty.

設定について

現時点でのバージョン1.0.0では、プラグインの設定画面はなくType of changeに表示する項目の取捨選択などはできないようです。

使ってみて

ダイアログ画面で入力した情報をテンプレートフォーマットに従ってコミットメッセージ欄に反映するというシンプルで使い易いプラグインでした。
ただ、初リリースから間もないということもあると思いますが、Typeの表示項目のカスタマイズができない点やタブでのフォーカスがすこし変な点(long
descriptionでタブを押すと次の欄にフォーカスせずにタブが入力される)は今後の機能拡張に期待したいです。

補足

Drupal - Open Source CMSの場合

DrupalというOSSでは、過去にコミットメッセージをAngularJSスタイルに変えようという提案があったようです。ある程度の規模のコミュニティでどのような議論が起きたのか興味深かったので補足としてリンクを載せておきます。

Drupalのコミットメッセージのガイドライン (Commit messages - providing history and credit)では、下記のように説明されていて、直近のコミットのメッセージもこのスタイルに沿っています。

Quick summary for the impatient
Use this syntax for commit messages:

Issue #[issue number] by [comma-separated usernames]: [Short summary of the change]

このドキュメントに関連する、2016年に投稿されたドキュメント([meta] Use the Git commit message format from AngularJS)では、コミットメッセージをAngularJSのスタイルに変更しようという提案がなされています。

この提案(ドキュメントのカテゴリはIssues)の結果が、どうなっているのかは調べ切れていませんが、ディスカッションも途絶えているようです。

6
4
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
6
4