如何正确关闭 Mercurial 中的功能分支?
我已经完成了功能分支 feature-x
的工作。我想将结果合并回默认分支并关闭feature-x,以便在hg分支的输出中删除它。
我提出了以下场景,但它有一些问题:
$ hg up default
$ hg merge feature-x
$ hg ci -m merge
$ hg up feature-x
$ hg ci -m 'Closed branch feature-x' --close-branch
因此 feature-x
分支(changests 40
-41
)已关闭,但有一个新头,即关闭分支变更集44
,每次都会在hg Heads
中列出:
$ hg log ...
o 44 Closed branch feature-x
|
| @ 43 merge
|/|
| o 42 Changeset C
| |
o | 41 Changeset 2
| |
o | 40 Changeset 1
|/
o 39 Changeset B
|
o 38 Changeset A
|
更新:从版本 1.5 开始,Mercurial 似乎不再在 hg Heads
的输出中显示闭合分支的头。
是否可以关闭合并分支而不留下更多头?有没有更正确的方法来关闭功能分支?
相关问题:
I've finished working on a feature branch feature-x
. I want to merge results back to the default
branch and close feature-x
in order to get rid of it in the output of hg branches
.
I came up with the following scenario, but it has some issues:
$ hg up default
$ hg merge feature-x
$ hg ci -m merge
$ hg up feature-x
$ hg ci -m 'Closed branch feature-x' --close-branch
So the feature-x
branch (changests 40
-41
) is closed, but there is one new head, the closing branch changeset 44
, that will be listed in hg heads
every time:
$ hg log ...
o 44 Closed branch feature-x
|
| @ 43 merge
|/|
| o 42 Changeset C
| |
o | 41 Changeset 2
| |
o | 40 Changeset 1
|/
o 39 Changeset B
|
o 38 Changeset A
|
Update: It appears that since version 1.5 Mercurial doesn't show heads of closed branches in the output of hg heads
anymore.
Is it possible to close a merged branch without leaving one more head? Is there more correct way to close a feature branch?
Related questions:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一种方法是让合并的功能分支保持打开状态(且不活动):
另一种方法是在使用额外提交进行合并之前关闭功能分支:
第一种方法更简单,但它会留下一个打开的分支。第二个没有留下任何开放的头/分支,但它需要一个辅助提交。人们可以使用
--close-branch
将对功能分支的最后一次实际提交与此额外提交结合起来,但应该提前知道哪个提交将是最后一个提交。更新:从 Mercurial 1.5 开始,您可以随时关闭分支,这样它就不会再同时出现在
hg 分支
和hg 头
中。唯一可能让您烦恼的是,从技术上讲,修订图仍将有一个没有子项的修订。更新 2:自 Mercurial 1.8 起,书签已成为 Mercurial 的核心功能。书签比命名分支更方便进行分支。另请参阅此问题:
One way is to just leave merged feature branches open (and inactive):
Another way is to close a feature branch before merging using an extra commit:
The first one is simpler, but it leaves an open branch. The second one leaves no open heads/branches, but it requires one more auxiliary commit. One may combine the last actual commit to the feature branch with this extra commit using
--close-branch
, but one should know in advance which commit will be the last one.Update: Since Mercurial 1.5 you can close the branch at any time so it will not appear in both
hg branches
andhg heads
anymore. The only thing that could possibly annoy you is that technically the revision graph will still have one more revision without childen.Update 2: Since Mercurial 1.8 bookmarks have become a core feature of Mercurial. Bookmarks are more convenient for branching than named branches. See also this question:
恕我直言,忘记关闭分支机构有两种情况
:情况 1:
分支没有合并到默认情况
下,在这种情况下,我更新到分支并使用 --close-branch 进行另一次提交,不幸的是,这会选择该分支成为新的提示,因此在将其推送到其他克隆之前,我确保真正的提示收到更多的变化,其他人不会对这个奇怪的提示感到困惑。
案例2:
分支已合并到默认情况下
这种情况与情况 1 没有太大区别,可以通过重复情况 1 和另外两个步骤的步骤来解决。
在这种情况下,我更新到分支变更集,使用 --close-branch 进行另一次提交,并将成为提示的新变更集合并到默认值中。最后一个操作在默认分支中创建了一个新提示 - 万岁!
希望这对未来的读者有所帮助。
imho there are two cases for branches that were forgot to close
Case 1:
branch was not merged into default
in this case I update to the branch and do another commit with --close-branch, unfortunatly this elects the branch to become the new tip and hence before pushing it to other clones I make sure that the real tip receives some more changes and others don't get confused about that strange tip.
Case 2:
branch was merged into default
This case is not that much different from case 1 and it can be solved by reproducing the steps for case 1 and two additional ones.
in this case I update to the branch changeset, do another commit with --close-branch and merge the new changeset that became the tip into default. the last operation creates a new tip that is in the default branch - HOORAY!
Hope this helps future readers.
编辑哎哟,太晚了...我知道阅读了您的评论,指出您希望保留功能x变更集,因此这里的克隆方法不起作用。
我仍然会把答案放在这里,因为它可能会帮助其他人。
如果您想完全摆脱“功能 X”,例如因为它不起作用,您可以克隆。这是文章中解释的方法之一,它确实有效,而且它专门讨论了头部。
据我了解,您有这个并且想要一劳永逸地摆脱“feature-x”头:
所以您这样做:
您将得到以下内容,并且您会看到 feature-x 确实是走了:
我可能误解了你想要的,但请不要修改,我花了时间重现你的用例:)
EDIT ouch, too late... I know read your comment stating that you want to keep the feature-x changeset around, so the cloning approach here doesn't work.
I'll still let the answer here for it may help others.
If you want to completely get rid of "feature X", because, for example, it didn't work, you can clone. This is one of the method explained in the article and it does work, and it talks specifically about heads.
As far as I understand you have this and want to get rid of the "feature-x" head once and for all:
So you do this:
And you'll have the following, and you'll see that feature-x is indeed gone:
I may have misunderstood what you wanted but please don't mod down, I took time reproducing your use case : )
奇怪的是,还没有人提出关闭功能分支的最可靠的方法......
您可以将合并提交与 --close-branch 标志结合起来(即提交修改的文件并同时关闭分支):
所以,就是这样。转速表上没有一个额外的头。没有额外的承诺。
It is strange, that no one yet has suggested the most robust way of closing a feature branches...
You can just combine merge commit with --close-branch flag (i.e. commit modified files and close the branch simultaneously):
So, that is all. No one extra head on revgraph. No extra commit.