git revert

git

書き方

git revert [-n] <commit>

打ち消す変更を新しいコミットとして足します。履歴を消さない点がポインタを動かすresetとの違いで、すでにpushしたものはrevertで戻します。

よく使うオプション

オプション意味
-nstage the inverse change without committing
-m <parent>which side to keep when reverting a merge commit
--no-editaccept the generated message
--continuefinish after resolving conflicts
--abortcancel and go back

git revert a1b2c3d

adds a new commit that undoes that one

git revert --no-edit HEAD

undoes the last commit without opening an editor

git revert -m 1 <merge-commit>

undoes a merge, keeping the first parent

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

読み方

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

よくある質問

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

打ち消す変更を新しいコミットとして足します。履歴を消さない点がポインタを動かすresetとの違いで、すでにpushしたものはrevertで戻します。

Q. どう打ちますか。

git revert [-n] <commit> — 角括弧は省いてよい部分です。

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

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

関連するコマンド

man ページ: man git-revert