Conventional Commits

概要

Conventional CommitsはGitなどVCSのコミットメッセージのための規約。 規則に従うことで自動化ツールを利用しやすくなる。

例: feat: allow optionalparams

コード化

Gitフックを使ってコード化すると、自然に慣らしていくことができる。

フォーマットを強制する

フォーマットに合ってないとき、コミットできないようにする。

.githooks/commit-msgを作成する。

#!/bin/sh
if ! head -1 "$1" | grep -qE "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\(.+?\))?: .{1,}$"; then
    echo "Aborting commit. Your commit message is invalid." >&2
    exit 1
fi
if ! head -1 "$1" | grep -qE "^.{1,50}$"; then
    echo "Aborting commit. Your commit message is too long." >&2
    exit 1
fi
$ git config --local core.hooksPath .githooks
$ chmod -R +x .githooks/

チートシートを表示する

慣れてないとtypeにどういうのがあったか忘れる。 コミット画面で、チートシートを表示する。

.githooks/commit_msg.txtを作成する。


# Conventional commits cheat sheet...
# build: ビルド
# chore: 雑事(カテゴライズする必要ないようなもの)
# ci: CI
# docs: ドキュメント
# feat: 新機能
# fix: バグフィックス
# perf: パフォーマンス
# refactor: リファクタリング
# revert: コミット取り消し(git revert)
# style: コードスタイル修正
# test: テスト

# https://www.conventionalcommits.org/ja/v1.0.0/
# https://gist.github.com/minop1205/5fc4f6ef0ec89fb1738833ba25ae00a0
$ git config --local commit.template .githooks/commit_msg.txt

Tasks

Reference

Archives