0
0

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

git を使った後にファイルが消えたときの対処法

Posted at

概要

ブランチからmasterブランチへ移動できていない状況で add、 commit、 push、 出現したエラーの対処などをして、その後エディタを開いたらファイルが1週間前の状態に戻っているように見えました。

対処法

git reflog を実行してcommitした履歴、resetした履歴、pullした履歴などを表示して状況を確認します。
新しい履歴が上から順に表示されます。

$ git reflog
66d7034 (origin/master, master) HEAD@{1}: commit: update file
6cb041e HEAD@{2}: commit: update file
33162bd HEAD@{4}: commit: add new file
56d4f81 HEAD@{5}: checkout: moving from 
56d4f81 HEAD@{6}: checkout: moving from master to origin/maste

戻りたい履歴の番号を把握して、 git checkout 戻りたい履歴の番号 を実行します。
例えば今回は 6cb041e まで戻したいので以下のように実行しました。

$ git checkout 6cb041e
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?