我正在寻找git提交的对应部分——在Mercurial中修改,即一种方法来修改我的工作副本链接到的提交。我只对最后一次提交感兴趣,而不是任意更早的提交。
修订程序的要求如下:
if possible, it should not require any extensions. It must not require non-default extensions, i.e. extensions which do not come with an official Mercurial installation.
if the commit to amend is one head of my current branch, no new head should be created. If the commit is not head, a new head may be created.
the procedure should be safe in a way that if for whatever reasons the amending fails, I want to have the same working copy and repository state restored as before the amending. With other words, if the amending itself can fail, there should be a fail-safe procedure to restore the working copy and repository state. I'm referring to "failures" which lie in the nature of the amend-procedure (like e.g. conflicts), not to file-system-related problems (like access restrictions, not being able to lock a file for writing, ...)
更新(1):
该过程必须是可自动化的,因此它可以由GUI客户端执行,而不需要任何用户交互。
更新(2):
工作目录中的文件不能被触摸(某些被修改的文件上可能存在文件系统锁)。这特别意味着,可能的方法在任何时候都不需要干净的工作目录。
假设您还没有传播您的更改,下面是您可以做的事情。
添加到你的.hgrc:
(扩展)
mq =
在你的存储库中:
Hg qimport -r0:tip
Hg qpop -a
当然你不需要从零版本或者弹出所有补丁开始,因为最后一个弹出(hg qpop)就足够了(见下文)。
删除.hg/patches/series文件中的最后一个条目,或者删除您不喜欢的补丁。重新排序也是可能的。
Hg qpush -a;Hg qfinish a
删除仍然在.hg/patches中的.diff文件(未应用的补丁)(在你的情况下应该是一个)。
如果你不想收回所有的补丁,你可以使用hg qimport -r0:tip(或类似的方法)编辑它,然后编辑东西并使用hg qrefresh将更改合并到堆栈的最上面的补丁中。阅读hg帮助qrefresh。
通过编辑.hg/patches/series,您甚至可以删除几个补丁,或重新排序一些补丁。如果你的最新版本是99,你可以使用hg qimport -r98:tip;hg qpop;[编辑系列文件];Hg qpush -a;Hg qfinish -a。
当然,这个过程是非常不鼓励和有风险的。在你这么做之前,把所有东西都备份一下!
作为旁注,我已经在仅私有存储库上做过无数次了。
在Mercurial 2.2版本中,您可以使用——amend选项和hg commit一起使用当前工作目录更新最后一次提交
从命令行引用:
The --amend flag can be used to amend the parent of the working directory with a new commit that contains the changes in the parent in addition to those currently reported by hg status, if there are any. The old commit is stored in a backup bundle in .hg/strip-backup (see hg help bundle and hg help unbundle on how to restore it).
Message, user and date are taken from the amended commit unless specified. When a message isn't specified on the command line, the editor will open with the message of the amended commit.
最重要的是,这种机制是“安全的”,因为它依赖于相对较新的“阶段”特性,以防止更新会改变本地存储库之外已经可用的历史。
Mercurial的最新版本包括了提供hg修正命令的evolve扩展。这允许修改提交而不丢失版本控制中的修改前历史。
hg amend [OPTION]... [FILE]...
aliases: refresh
combine a changeset with updates and replace it with a new one
Commits a new changeset incorporating both the changes to the given files
and all the changes from the current parent changeset into the repository.
See 'hg commit' for details about committing changes.
If you don't specify -m, the parent's message will be reused.
Behind the scenes, Mercurial first commits the update as a regular child
of the current parent. Then it creates a new commit on the parent's
parents with the updated contents. Then it changes the working copy parent
to this new combined changeset. Finally, the old changeset and its update
are hidden from 'hg log' (unless you use --hidden with log).
有关evolve扩展的完整描述,请参阅https://www.mercurial-scm.org/doc/evolution/user-guide.html#example-3-amend-a-changeset-with-evolve。