如何在git硬重置后恢复上次提交?

如何在git硬重置后恢复上次提交?,git,Git,我可以在硬重置后恢复以下提交吗 步骤: 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-bran

我可以在硬重置后恢复以下提交吗

步骤:

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

有没有办法从混乱中恢复我的更改?

git reflog是否显示了缺少提交的哈希值?如果是,那么
git checkout-b recovery branch commitId
将创建一个指向缺少的提交的新分支。然后,您可以根据需要进行合并。

每当git做一些剧烈的事情,比如更改或重绕分支时,它都会在reflog中记录下来。换句话说,仔细检查git reflog的输出,它将告诉您分支有过的所有转换。然后,您可以使用
git show commit\u id
检查并
git checkout commit\u id
返回。

老实说,我不知道发生了什么

git reflog
打印提交分支指向的内容。
您可以使用它来查找最近本地提交的SHA1总和。

要查看对001分支所做的所有更改,您可以执行
git reflog 001分支
,但是,很可能是您认为您在001分支中所做的,可能是您执行了另一个分支,因此,您可能需要使用
git reflog

查看所有更改。有几个问题:(1)步骤4中的提交是否成功?(2) 你是否真的在第8步做了一个重基?(3) 什么是“所有的kiboshed”?您是否看到在第4步中进行的提交,它是以某种方式损坏的,还是只是丢失了?(4) 您是否在001分支的
git reflog
中看到您的提交?reflog是摆脱这类事情的常用方法。谢谢reflog,它回来了,这能回答你的问题吗?是的,就是这样。我可以通过reflog把它取回来。非常感谢。谢谢我把它拿回来了!