0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Git】git reset --hard HEADで消してしまったコミット時点まで戻る

Posted at

はじめに

git reset --hard HEADでコミット地点まで戻った時、そのコミット以降のコミットが全て削除されていて焦りました。
そのため削除してしまったコミット地点まで戻る方法を書き残します。

方法

git reflogコマンドで全ての変更ログを出力します。

$ git reflog

03a4dbb HEAD@{1}: reset: moving to 03a4dbbfd50be3d6ba98f1e652398298f35bc348
03a4dbb HEAD@{2}: reset: moving to 03a4dbbfd50be3d6ba98f1e652398298f35bc348
097ebfb HEAD@{3}: checkout: moving from master to task-title-memory

上記のHEAD@{2}でコミットをリセットしています。リセット前まで戻るにはその一つ前の変更地点の識別子でリセットします。

$ git reset --hard 097ebfb

これで元に戻せました。

参考

0
1
0

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?