Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ コミットメッセージ | Git入門
Gitの基礎

コミットメッセージ

メニューを表示するにはスワイプしてください

コミットメッセージが重要な理由

コミットメッセージは、プロジェクトの履歴を理解するために不可欠。 明確で意味のあるメッセージは、協力者や将来の開発者、そして自分自身が各変更の目的背景を把握するのに役立つ。 構造化されたコミット履歴は、コラボレーションを促進し、デバッグを簡素化し、プロジェクトのタイムラインで特定の変更を追跡しやすくする。

良いコミットメッセージの構成

1. 簡潔さと明確さ

コミットメッセージは簡潔で要点を押さえる必要がある。コミットの目的を一行で明確に伝えるべき。 曖昧さを避け、実際のコードを見なくても変更内容が理解できる十分な情報を提供する。

Bad: "Fixed a bug"
Good: "Fix issue with user authentication in login form"

2. 件名と本文の分離

詳細が必要な場合は、件名本文を空行で分ける。件名は変更内容を要約し、本文には追加の背景や変更理由、関連情報を記載する。

このようなコミットメッセージの例を見てみよう:

Subject: "Add validation for user email input"

Body: "This commit introduces email format validation to ensure
that users provide a valid email address when registering. It
helps improve the overall data integrity of the system."

この場合、git commitフラグなしで -m コマンドを実行する:

git commit

Gitのデフォルトのテキストエディタが開き、詳細なコミットメッセージを記述できます。その後、保存して適切にテキストエディタを終了してください。

リポジトリで別のコミットを作成します:

テキストファイルを変更するために使用されるコマンド:

echo "Git is the most popular VCS in the world used by millions of developers since it allows efficient collaboration via committing, reverting and merging changes. Besides, Git is free and open source and can be easily installed on Windows, macOS, Linux and all Unix-based platforms." >> test.txt

コミットメッセージは以下の通り:

Subject: "Add description of Git"
  
Body: "This commit introduces brief description 
of Git and highlights its key features. It also 
states the reasons for the widespread popularity 
of Git."

ファイルを編集できない場合は、i キーを押してください。これにより編集モードに入ります。変更を保存して Vim を終了するには、Escape キーと大文字の Z を2回押します。

Note
注意

ターミナルのデフォルトテキストエディタが Vim 以外の場合や操作に困った場合は、インターネットで保存方法や終了方法を簡単に調べることができます。

3. 命令形の使用

コミットメッセージは命令形で記述し、変更の方向性を示します。件名は "Fix"、"Add"、"Update" などの動詞で始めます。

Bad: "Fixed the issue with the login form"
Good: "Fix issue with user authentication in login form"
question mark

コミットメッセージにおいて、簡潔さと明確さを最もよく示しているアプローチはどれですか?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  10

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  10
some-alt