撤消 'git reset <sha>'
Undoing 'git reset <sha>'
我做了一个
git reset <sha>
回到我存储库中的一个相当旧的 sha,我想回到旧的 head。我怎么做?如果我做一个
git pull
这样行吗?
此外,我的存储库中现在有很多未暂存的文件。
问题是,当您将状态重置回较早的状态时,您会丢失历史记录。所以你看不到更新的提交。你能做的就是把你说的再拉一遍。然后从远程存储库中提取所有更新的更改。
其他解决方案是使用 reflog 恢复未链接的提交。
https://www.atlassian.com/git/tutorials/rewriting-history/git-reflog
来自 Atlassian 页面的示例:
#git reflog
0a2e358 HEAD@{0}: reset: moving to HEAD~2
0254ea7 HEAD@{1}: checkout: moving from 2.2 to master
c10f740 HEAD@{2}: checkout: moving from master to 2.2
然后您可以搜索条目并恢复它。
#git 重置 --hard 0254ea7
我做了一个
git reset <sha>
回到我存储库中的一个相当旧的 sha,我想回到旧的 head。我怎么做?如果我做一个
git pull
这样行吗?
此外,我的存储库中现在有很多未暂存的文件。
问题是,当您将状态重置回较早的状态时,您会丢失历史记录。所以你看不到更新的提交。你能做的就是把你说的再拉一遍。然后从远程存储库中提取所有更新的更改。
其他解决方案是使用 reflog 恢复未链接的提交。
https://www.atlassian.com/git/tutorials/rewriting-history/git-reflog
来自 Atlassian 页面的示例:
#git reflog
0a2e358 HEAD@{0}: reset: moving to HEAD~2
0254ea7 HEAD@{1}: checkout: moving from 2.2 to master
c10f740 HEAD@{2}: checkout: moving from master to 2.2
然后您可以搜索条目并恢复它。
#git 重置 --hard 0254ea7