559
449

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 5 years have passed since last update.

GitAdvent Calendar 2012

Day 29

いざという時のためのgit reflog

Last updated at Posted at 2012-07-01

Git Advent Calendar / Jun. 29日目の記事です.28日目は@uasiさんの「どこでも使える git diff と git apply」でした.

「間違ってマージしていないブランチを消した」「reset --hard HEAD^*で戻しすぎた」ということがたまにある.
しかしgit reflogを使うと(GCされていなければ)過去のあらゆるコミット履歴を見ることができ,git logやgit branchでは辿り着けない時点まで戻すことができる.

$ git reset --hard HEAD^^ # HEAD^と指定するつもりが間違えた!
$ git reflog
f5cb888 HEAD@{0}: head^^: updating HEAD
b0b8073 HEAD@{1}: merge @{-1}: Merge made by the 'recursive' strategy.
fe3972d HEAD@{2}: checkout: moving from fix/some-bug to master
$ git reset --hard HEAD@{1} # reset --hard HEAD^^する前に戻れる

歴史を書き換え間違えたときのために覚えておくと便利!

559
449
6

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
559
449

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?