Gitの使い方が解る git commitとCommitコメント

前回、Staging Area の操作をやりました。Staging Area でステージしたファイルは Commit しなければいけません。
今回は Commit について見ていきたいと思います。
目次
git commit -m “コミット内容の説明”
git commit の基本はこのコマンドでOKです。
git commit -m "コミット内容の説明"
実行例
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: sample.txt
まだコミットされていない状態のファイルをコミットしてみます。
$ git commit -m "first commit"
[master (root-commit) 68a9614] first commit
1 file changed, 1 insertion(+)
create mode 100644 sample.txt
これだけです。これでコミット完了です。
$ git log
commit 68a9614a11f2c755e1fd48e837f2d9d4519098cb (HEAD -> master)
Author: waku <waku@waku.nagoya>
Date: Sat Feb 27 11:45:04 2021 +0900
first commit
このようにコミットされたことが確認できました。
git commit のコメントについて
git commit で一番悩むのはどんなコメントを書くかということかと思います。決まりはないのですが、慣習というものがあって、ここで説明しだすとだいぶ横道に逸れてしまいそうなので、簡単に説明して、あとは参考サイトを紹介します。
先ほどは git commit -m "コミット内容の説明"
でコミットしましたが、-m
オプションを使わないとエディタが起動します。
# 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:
# new file: .gitignore
# modified: sample.txt
#
# Untracked files:
# #sample.txt#
#
ここで1行目に概要を書きます。2行目は空白で、3行目にコミット内容の詳細を書きます。
概要の最初にはプレフィックスをつけます。だいたいこんな感じで良いでしょう。
プレフィックス | 内容 |
---|---|
Fix | バグ修正 |
Add | 新規ファイル追加、新規機能追加 |
Update | ドキュメントなどバグではない修正 |
Remove | ファイル削除、コードの一部を削除 |
Change | 仕様変更 |
Move | ファイル移動 |
他にも色々ありますが、次の参考サイトに譲ります。
git commit コメントの書き方 参考サイト
[転載] gitにおけるコミットログ/メッセージ例文集100
git commit コメントを修正する方法
https://www.granfairs.com/blog/staff/git-commit-fix
-
前の記事
Gitの使い方が解る Staging Areaの操作 2021.02.14
-
次の記事
WordPressをEC2のt3.nanoで稼働してたらMySQLがOut of memoryになった話 2022.02.16