git commit

git

書き方

git commit [-a] -m "<message>"

ステージに載せたものだけを一つのコミットとして記録します。-aは追跡中のファイルしか拾わないので、新しく作ったファイルは入りません。

よく使うオプション

オプション意味
-m "<msg>"give the message on the command line
-astage modified tracked files first; new files are skipped
--amendreplace the previous commit instead of adding one
--no-editkeep the old message, used with --amend
--fixup=<commit>mark it to be folded into <commit> by rebase --autosquash
-Ssign the commit with GPG
--allow-emptycommit with nothing staged

git commit -m "fix login redirect"

records what is staged

git commit -a -m "typo"

stages tracked edits and commits in one step

git commit --amend --no-edit

folds the staged change into the last commit, keeping its message

取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. git commit は何をしますか。

ステージに載せたものだけを一つのコミットとして記録します。-aは追跡中のファイルしか拾わないので、新しく作ったファイルは入りません。

Q. どう打ちますか。

git commit [-a] -m "<message>" — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは7個です。全部は man git にあります。このコマンドはgitの仲間です。

関連するコマンド

man ページ: man git-commit