如何撤消 Git 回滚
我想在犯了一个大错误后回滚到最后一次提交,但我设法回滚有点太公平了。当我在 bash 中输入“git log”时,我想要重新断言的提交不会出现(我想是因为它不再出现在历史记录中)。有什么办法可以恢复上次提交的日期吗?
我还在 eclipse 中使用 eGit 来完成同一个项目,如果这能让事情变得更容易的话。谢谢。
I wanted to rollback to the last commit after making a massive error, but I managed to rollback a little too fair. The commit I wanted to reassert doesn't appear when I enter 'git log' in bash (I suppose because it's no longer in the history). Is there any way I can recover the last commit by date?
I'm also using eGit in eclipse for the same project if that makes things easier. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您可以使用命令行,请转到您的存储库,执行 git reflog 并获取您想要“回滚”的提交,然后执行 git reset --hard;
您还可以执行
git reset --hard HEAD@{1}
然后返回 egit 并回滚到所需的提交。If you are ok with command line, go to you repo, do a
git reflog
and get the commit which you want to "rollback" to and do agit reset --hard <commit>
You would also be able to do
git reset --hard HEAD@{1}
and then come back to egit and rollback to the desired commit.我发现通常最好及时向前做出更改,而不是向后更改。
Git 的方法是“恢复”提交。当您恢复提交时,您将相关提交的相反签入工作目录。然后你添加并提交它,你刚刚做了一个新的提交,它提交了你正在恢复的提交的“撤消”,并且它在历史中留下了这样的事情发生的记录,所以如果你想撤消你的毁灭,很容易做到。
I find that generally it's better to make your changes forward in time rather than backward.
Git's approach is to "revert" the commit. When you revert a commit, you check out into your working directory the inverse of the commit in question. Then you add and commit that, and you've just made a NEW commit, that commits the "undoing" of the commit you're reverting, AND it leaves a record in history that such a thing happened, so if you want to undo your undoing, it's easy to do.