Mercurial 撤消最后一次提交

标签 mercurial tortoisehg mercurial-commit

如何撤消 Mercurial 中上次意外提交(未推送)的更改?

如果可能的话,最好使用 TortoiseHg 来实现这一点。

更新

在我的具体案例中,我提交了一个变更集(未推送)。然后我从服务器上拉取并更新。通过这些新的更新,我决定我的上次提交已过时,我不想同步它。所以看来,hg rollback并不正是我正在寻找的,因为它会回滚拉取而不是我的提交。

最佳答案

一种方法是 hg rollback (自 2013 年 8 月 Hg2.7 起已弃用)

Please use hg commit --amend instead of rollback to correct mistakes in the last commit.

Roll back the last transaction in a repository.

When committing or merging, Mercurial adds the changeset entry last.
Mercurial keeps a transaction log of the name of each file touched and its length prior to the transaction. On abort, it truncates each file to its prior length. This simplicity is one benefit of making revlogs append-only. The transaction journal also allows an undo operation.

参见TortoiseHg Recovery section :

alt text

This thread还详细介绍了 hg rollbackhg strip 之间的区别:
(由 Martin Geisler 撰写,他也对 SO 做出了贡献)

  • 'hg rollback' will remove the last transaction. Transactions are a concept often found in databases. In Mercurial we start a transaction when certain operations are run, such as commit, push, pull...
    When the operation finishes succesfully, the transaction is marked as complete. If an error occurs, the transaction is "rolled back" and the repository is left in the same state as before.
    You can manually trigger a rollback with 'hg rollback'. This will undo the last transactional command. If a pull command brought 10 new changesets into the repository on different branches, then 'hg rollback' will remove them all. Please note: there is no backup when you rollback a transaction!

  • 'hg strip' will remove a changeset and all its descendants. The changesets are saved as a bundle, which you can apply again if you need them back.

ForeverWintr在评论中建议(2016年,5年后)

You can 'un-commit' files by first hg forgetting them, e.g.: hg forget filea; hg commit --amend, but that seems unintuitive.
hg strip --keep is probably a better solution for modern hg.

关于Mercurial 撤消最后一次提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4760684/

相关文章:

ssh - Mercurial Hg没有因远程Hg错误而引起的适当响应

mercurial - 如何将分支更新为 Mercurial 中不同分支上标签的状态?

mercurial - 如何使 hg 忽略过滤器不区分大小写

version-control - 如何在 Mercurial 中编辑不正确的提交消息?

configuration - TortoiseHg无法提交--"The system cannot find the file specified"

Mercurial 提交和 merge

Mercurial 和代码审查;良好的工作流程?

version-control - 在 Windows 中安装 SCM Manager(Mercurial 管理 Web 前端)

mercurial - 您如何列出 mercurial 存储库中已更改的所有文件,仅限于草稿变更集?

mercurial - Windows 7上的Hg TortoiseHg提交错误