LoginSignup
75
53

More than 5 years have passed since last update.

Gitで直近のコミットをコミット前に戻すにはgit reset @~

Last updated at Posted at 2018-07-05

Gitで直近のコミットをなかったことにし、コミット前の状態に戻す方法です。

このようなコミットがある状況で:

* 40c620d 2018-07-05 suin commit 4
* ea300fa 2018-07-05 suin commit 3
* bd03840 2018-07-05 suin commit 2
* 76c4199 2018-07-05 suin commit 1

次のコマンドを実行すると:

git reset --soft @~

「commit 4」が消えてこうなります:

* ea300fa 2018-07-05 suin commit 3
* bd03840 2018-07-05 suin commit 2
* 76c4199 2018-07-05 suin commit 1

「commit 4」で加えられた変更はステージされた状態(git addされた状態)になります。

75
53
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
75
53