概要
コミットメッセージの内容を揃えることを目的にGitのコミットメッセージテンプレートを作成し登録します。
そうすることでコミットの際に「こう言うことを書けばいいんだな」と意識できます。
さらに、絵文字Prefixを使っているのであればこの絵文字はこう言う意味だよみたいなものをコミットの際に表示させることができます。
業務としてGitを使った開発をしなければ一生、目に触れることのない知識だったでしょう。
目次
参考サイト様
commit message templateの作成&登録
commit message template自体はパスを指定してGitに読み込ませるので任意のディレクトリに作成して構いません。
今回はmy-cheatsheet 🔗のプロジェクトルートに配置します。
また、このプロジェクトのみでテンプレートが有効になるように設定します。(この部分については後述します)
commit message templateの作成
# 任意のファイル名で構わない。
$ vi .gitmessage
Gistにテンプレートのテンプレート(?)があるのでそのまま使います。
そのうち個人用にカスタマイズします。(絵文字の一覧表にしたいだけなんですがね…笑)
- 参考:[.gitmessage 🔗]
[branchname]
# ==== Emojis ====
# ✏️ :pencil2: Writing docs
# 🐛 :bug: Fix bugs
# 👍 :+1: Feature improvements
# ✨ :sparkles: Additional partial feature
# 🎉 :tada: Grand major features added to celebrate
# ♻️ :recycle :Refactoring
# 🚿 :shower: Removal of obsolete functions or features.
# 💚 :green_heart: Modification and improvement of testing and CI
# 👕 :shirt: Fixing of errors found by Lint.
# 🚀 :rocket: Performance improvement
# 🆙 :up: Updates, such as dependent package
# 🔒 :lock: Limit of the range of new features
# 👮 :cop: Security-related improvements
# ==== Format ====
# :emoji: Subject #issue No.
#
# Commit body...
# ==== The Seven Rules ====
# 1. Separate subject from body with a blank line
# 2. Limit the subject line to 50 characters
# 3. Capitalize the subject line
# 4. Do not end the subject line with a period
# 5. Use the imperative mood in the subject line
# 6. Wrap the body at 72 characters
# 7. Use the body to explain what and why vs. how
#
# How to Write a Git Commit Message http://chris.beams.io/posts/git-commit/
# for http://memo.goodpatch.co/2016/07/beautiful-commits-with-emojis/
commit message templateの登録
git config
に先程作成したテンプレートを登録します。
$ git config commit.template .gitmessage
PCに存在するGit管理のすべてのプロジェクトにテンプレートを適用したい場合は、--global
を付与して全体に適用します。
今回は該当のプロジェクトに適用させたいだけなのでプロジェクトディレクトリで作業しています。
commit message templateを使ってcommit
何かしらプロジェクトのファイルに変更を加えてstagingさせたらコミットしてみましょう。
$ git commit
これでエディタが立ち上がってテンプレートが表示されます。
[branchname]
# ==== Emojis ====
# ✏️ :pencil2: Writing docs
# 🐛 :bug: Fix bugs
# 👍 :+1: Feature improvements
// 省略
ここに好き勝手書いてしまいましょう。
私はいつもgit commit -m 'コミットメッセージ'
でコミットしていたのでコミットメッセージを複数行に渡って書けるんだと言う新しい発見もありました。
雑感
週末になってやっと小さな記事を書くことができました。
ホテル暮らしから待ち望んだ引っ越しが終わって本格的に一人暮らしがスタートしました。
実家ぐらしの最強さ、母の偉大さを痛感しつつ日々必死に労働しています。