gpt4 book ai didi

Mercurial 撤消最后一次提交

转载 作者:行者123 更新时间:2023-12-02 22:13:28 24 4
gpt4 key购买 nike

如何撤消 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com