18

ハードリセット後に次のコミットを回復できますか?

手順:

1) $ (master) // ....made a bunch of changes to files thinking I was working on a branch
2) $ git checkout -b 001-branch  // copy changes to a branch to work with
3) $ (001-branch) // make some more changes to files
4) $ (001-branch) git commit -a -m 'added and changed stuff'
// at this point I was just going to pull force master to latest then rebase my 001-branch off of original master (not the stuff I had modified)
5) $ (001-branch) git checkout master
6) $ (master) git reset --hard HEAD
7) $ (master) git pull
8) $ (master) git checkout 001-branch // go back to my branch and rebase my changes
9) $ (001-branch) // oops...my changes were all kiboshed and I don't see the commit I did per git lg

この混乱から私の変更を回復する方法はありますか?

4

4 に答える 4

19

001-branch に加えられたすべての変更を表示するには、 を実行できgit reflog 001-branchますgit reflog

于 2013-11-11T04:04:23.553 に答える
15

git reflog show不足しているコミットのハッシュを出力しますか? はいの場合git checkout -b recovery-branch commitId、不足しているコミットを指す新しいブランチを作成します。その後、必要に応じてマージできます。

于 2013-11-11T04:00:30.247 に答える
5

git がブランチの変更や巻き戻しなどの抜本的な操作を行うたびに、それを reflog に記録します。つまり、 の出力を注意深く調べるとgit reflog、これまでに分岐したすべてのトランジションが表示されます。その後、 を使用git show commit_idして調べてgit checkout commit_id戻ることができます。

于 2013-11-11T04:00:52.493 に答える
4

正直なところ、何が起こったのか理解できません。

git reflogブランチが指していたコミットを出力します。これを使用して、最近のローカルコミットの SHA1 合計を見つけることができます。

于 2013-11-11T04:00:55.390 に答える