我目前正在使用TortoiseHg (Mercurial),不小心提交了一个错误的提交消息。如何在存储库中编辑这条提交消息?


当前回答

In TortoiseHg, right-click on the revision you want to modify. Choose Modify History->Import MQ. That will convert all the revisions up to and including the selected revision from Mercurial changesets into Mercurial Queue patches. Select the Patch you want to modify the message for, and it should automatically change the screen to the MQ editor. Edit the message which is in the middle of the screen, then click QRefresh. Finally, right click on the patch and choose Modify History->Finish Patch, which will convert it from a patch back into a change set.

哦,这里假设MQ是这个存储库上TortoiseHG的活动扩展。如果没有,您应该能够单击File->Settings,单击Extensions,然后单击mq复选框。它应该警告你,你必须关闭TortoiseHg之前的扩展是活跃的,所以关闭并重新开放。

其他回答

我以前是这么做的:

想象一下,您有500个提交,错误的提交消息在r.498中。

hg qimport -r 498:tip
hg qpop -a
joe .hg/patches/498.diff
(change the comment, after the mercurial header)
hg qpush -a
hg qdelete -r qbase:qtip

上面讨论的一个小宝石-感谢@Codest和@Kevin Pullin。 在TortoiseHg中,在提交按钮旁边有一个下拉选项。选择“修正当前修订”会带回注释和文件列表。所以有用。

使用MQ扩展和调试命令还有另一种方法。这是在不丢失数据的情况下修改历史记录的一种通用方法。让我假设和安东尼奥的情况一样。

// set current tip to rev 497
hg debugsetparents 497
hg debugrebuildstate
// hg add/remove if needed
hg commit
hg strip [-n] 498

In TortoiseHg, right-click on the revision you want to modify. Choose Modify History->Import MQ. That will convert all the revisions up to and including the selected revision from Mercurial changesets into Mercurial Queue patches. Select the Patch you want to modify the message for, and it should automatically change the screen to the MQ editor. Edit the message which is in the middle of the screen, then click QRefresh. Finally, right click on the patch and choose Modify History->Finish Patch, which will convert it from a patch back into a change set.

哦,这里假设MQ是这个存储库上TortoiseHG的活动扩展。如果没有,您应该能够单击File->Settings,单击Extensions,然后单击mq复选框。它应该警告你,你必须关闭TortoiseHg之前的扩展是活跃的,所以关闭并重新开放。

如果我想编辑的版本不是那么旧,我会使用一个hack:

假设你的转速是500,而你想编辑497。

hg export -o rev497 497
hg export -o rev498 498
hg export -o rev499 499
hg export -o rev500 500

编辑rev497文件并更改消息。(它位于以“#”开头的第一行之后)

hg import rev497
hg import rev498
hg import rev499
hg import rev500