如何撤消 Git 回滚

发布于 2024-11-19 06:27:06 字数 172 浏览 4 评论 0原文

我想在犯了一个大错误后回滚到最后一次提交,但我设法回滚有点太公平了。当我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁把谁当真 2024-11-26 06:27:06

如果您可以使用命令行,请转到您的存储库,执行 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 a git 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.

缱绻入梦 2024-11-26 06:27:06

我发现通常最好及时向前做出更改,而不是向后更改。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文