如何在 Mercurial 中创建非提示修订分支?
在我的存储库中,我有修订版 1 到 10。我已推送到修订版 5(因此下一个 hg 推送
将发布修订版 6-10)。
但我现在必须中断我的工作,结果还没有100%完成。因此,我想将修订版 6-10 移至新的“实验”分支,以允许其他人在不中断每个人的源代码的情况下完成工作。
如何将分支添加到非提示修订版(在我的例子中:从修订版 6 开始)?或者我应该使用完全不同的方法?
In my repo, I have the revisions 1 to 10. I've pushed up to 5 (so the next hg push
would publish revisions 6-10).
But I have to interrupt my work now and the result isn't 100% complete. So I'd like to move the revisions 6-10 into a new "experimental" branch to allow someone else to complete the work without disrupting the sources for everyone.
How can I add a branch to a non-tip revision (in my case: Starting with revision 6)? Or should I use a completely different approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法在不修改历史记录的情况下应用分支名称。
最简单的方法是要求其他用户使用修订版 5 作为他们创建的任何更改的父版本。例如,其他用户将:
hg clone
甚至hg clone --rev 5
hg update -r 5
hg commit
当他们提交更改时,它将在
default
分支上创建第二个头,但这不会产生任何问题。实验性更改完成后,您只需将两个头合并在一起即可。话虽这么说,将变更集移动到分支上可以使用 Mercurial 队列 (MQ) 来完成。以下序列显示了如何完成:
hg qinit
(创建新的补丁队列)hg qimport --rev 6:10
(将 r6-10 导入新的补丁队列)hg qpop -a
(从工作副本中删除所有补丁)hgbranch <分支名称>
(创建新的实验分支)hg qpush -a< /code> (将所有补丁应用到您的分支)
hg qfinish -a
(将所有补丁转换为永久变更集)You cannot apply a branch name after the fact without modifying your history.
The most simple approach is to ask the other users to use revision 5 as the parent for any changes they create. For example, the other users would:
hg clone <your repo>
or evenhg clone --rev 5
hg update -r 5
hg commit
When they commit a change, it will create a second head on the
default
branch, but that should not create any problems. You will simply need to merge the two heads together once your experimental changes are complete.That being said, moving your changesets onto a branch can be accomplished using Mercurial Queues (MQ). The following sequence shows how it be done:
hg qinit
(Create a new patch queue)hg qimport --rev 6:10
(import r6-10 into a new patch queue)hg qpop -a
(remove all patches from your working copy)hg branch <branch name>
(create your new experimental branch)hg qpush -a
(apply all the patches to your branch)hg qfinish -a
(convert all patches to permanent changesets)蒂姆已经有了很好的建议。此外,您可以将您的实验性更改推送到中央服务器上的一个不同的实验克隆中(我猜您使用了一个)。其他开发人员也可以使用此克隆来推送他们尚未完成的工作,以便其他人审查或继续它。同样明显的是,这个克隆的代码还没有准备好使用。一旦某个任务完成,相应的变更集就可以被推送到稳定存储库。
实际上命名分支对于您的情况来说是一个好主意,但事实上它们的名称被铭刻在历史中,这更多的是一个问题而不是一个功能。恕我直言,Git 的分支名称更实用。然而,在某种程度上,您也可以使用书签来处理您的情况,从 Mercurial 1.7 开始就可以推送书签(此处不确定)。也就是说,您可以使用诸如稳定之类的内容(或者您在团队中同意的任何内容)为修订版5添加书签,并且可以使用诸如Aarons-not-finished-work之类的内容为修订版10添加书签。然后,其他开发人员只会拉稳定,除了您的同事,他应该继续您的工作,他会拉另一个书签。然而,我个人还没有使用过这样的工作流程,所以我不能说它在实践中是否表现良好。
Tim already has good suggestions. Additionally you could push your experimental changes into a distinct experimental clone on your central server (I guess you use one). This clone could also be used by other developers to push their not-yet-finished work in order to let others review or continue it. It is also clear that this clone's code is not ready to be used. Once some task is finished, the corresponding changesets can be pushed to the stable repository.
Actually named branches are a good idea for your case, but the fact that their names are burned into history mostly is more a problem than a feature. IMHO Git's branch names are more practically. However, to some extend you could also handle your case with bookmarks, which are pushable since Mercurial 1.7 (not sure here). That is you bookmark revision 5 with something like stable (or whatever you agree on in your team) and revision 10 gets bookmarked with something like Aarons-not-finished-work. The other developers would then just pull stable, except your colleague who is supposed to continue your work, who would pull the other bookmark. However, personally I did not use a such workflow yet, so I cannot say if it performs well in practice.