如何正确关闭 Mercurial 中的功能分支?

发布于 2024-08-20 22:08:19 字数 962 浏览 3 评论 0原文

我已经完成了功能分支 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一曲爱恨情仇 2024-08-27 22:08:19

一种方法是让合并的功能分支保持打开状态(且不活动):

$ hg up default
$ hg merge feature-x
$ hg ci -m merge

$ hg heads
    (1 head)

$ hg branches
default    43:...
feature-x  41:...
    (2 branches)

$ hg branches -a
default    43:...
    (1 branch)

另一种方法是在使用额外提交进行合并之前关闭功能分支:

$ hg up feature-x
$ hg ci -m 'Closed branch feature-x' --close-branch
$ hg up default
$ hg merge feature-x
$ hg ci -m merge

$ hg heads
    (1 head)

$ hg branches
default    43:...
    (1 branch)

第一种方法更简单,但它会留下一个打开的分支。第二个没有留下任何开放的头/分支,但它需要一个辅助提交。人们可以使用 --close-branch 将对功能分支的最后一次实际提交与此额外提交结合起来,但应该提前知道哪个提交将是最后一个提交。

更新:从 Mercurial 1.5 开始,您可以随时关闭分支,这样它就不会再同时出现在 hg 分支hg 头 中。唯一可能让您烦恼的是,从技术上讲,修订图仍将有一个没有子项的修订。

更新 2:自 Mercurial 1.8 起,书签已成为 Mercurial 的核心功能。书签比命名分支更方便进行分支。另请参阅此问题:

One way is to just leave merged feature branches open (and inactive):

$ hg up default
$ hg merge feature-x
$ hg ci -m merge

$ hg heads
    (1 head)

$ hg branches
default    43:...
feature-x  41:...
    (2 branches)

$ hg branches -a
default    43:...
    (1 branch)

Another way is to close a feature branch before merging using an extra commit:

$ hg up feature-x
$ hg ci -m 'Closed branch feature-x' --close-branch
$ hg up default
$ hg merge feature-x
$ hg ci -m merge

$ hg heads
    (1 head)

$ hg branches
default    43:...
    (1 branch)

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 and hg 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:

往昔成烟 2024-08-27 22:08:19

恕我直言,忘记关闭分支机构有两种情况

:情况 1:
分支没有合并到默认情况

下,在这种情况下,我更新到分支并使用 --close-branch 进行另一次提交,不幸的是,这会选择该分支成为新的提示,因此在将其推送到其他克隆之前,我确保真正的提示收到更多的变化,其他人不会对这个奇怪的提示感到困惑。

hg up myBranch
hg commit --close-branch

案例2:
分支已合并到默认情况下

这种情况与情况 1 没有太大区别,可以通过重复情况 1 和另外两个步骤的步骤来解决。

在这种情况下,我更新到分支变更集,使用 --close-branch 进行另一次提交,并将成为提示的新变更集合并到默认值中。最后一个操作在默认分支中创建了一个新提示 - 万岁!

hg up myBranch
hg commit --close-branch
hg up default
hg merge myBranch

希望这对未来的读者有所帮助。

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.

hg up myBranch
hg commit --close-branch

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!

hg up myBranch
hg commit --close-branch
hg up default
hg merge myBranch

Hope this helps future readers.

思慕 2024-08-27 22:08:19

编辑哎哟,太晚了...我知道阅读了您的评论,指出您希望保留功能x变更集,因此这里的克隆方法不起作用。

我仍然会把答案放在这里,因为它可能会帮助其他人。

如果您想完全摆脱“功能 X”,例如因为它不起作用,您可以克隆。这是文章中解释的方法之一,它确实有效,而且它专门讨论了头部。

据我了解,您有这个并且想要一劳永逸地摆脱“feature-x”头:

@    changeset:   7:00a7f69c8335
|\   tag:         tip
| |  parent:      4:31b6f976956b
| |  parent:      2:0a834fa43688
| |  summary:     merge
| |
| | o  changeset:   5:013a3e954cfd
| |/   summary:     Closed branch feature-x
| |
| o  changeset:   4:31b6f976956b
| |  summary:     Changeset2
| |
| o  changeset:   3:5cb34be9e777
| |  parent:      1:1cc843e7f4b5
| |  summary:     Changeset 1
| |
o |  changeset:   2:0a834fa43688
|/   summary:     Changeset C
|
o  changeset:   1:1cc843e7f4b5
|  summary:     Changeset B
|
o  changeset:   0:a9afb25eaede
   summary:     Changeset A

所以您这样做:

hg clone . ../cleanedrepo --rev 7

您将得到以下内容,并且您会看到 feature-x 确实是走了:

@    changeset:   5:00a7f69c8335
|\   tag:         tip
| |  parent:      4:31b6f976956b
| |  parent:      2:0a834fa43688
| |  summary:     merge
| |
| o  changeset:   4:31b6f976956b
| |  summary:     Changeset2
| |
| o  changeset:   3:5cb34be9e777
| |  parent:      1:1cc843e7f4b5
| |  summary:     Changeset 1
| |
o |  changeset:   2:0a834fa43688
|/   summary:     Changeset C
|
o  changeset:   1:1cc843e7f4b5
|  summary:     Changeset B
|
o  changeset:   0:a9afb25eaede
   summary:     Changeset A

我可能误解了你想要的,但请不要修改,我花了时间重现你的用例:)

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:

@    changeset:   7:00a7f69c8335
|\   tag:         tip
| |  parent:      4:31b6f976956b
| |  parent:      2:0a834fa43688
| |  summary:     merge
| |
| | o  changeset:   5:013a3e954cfd
| |/   summary:     Closed branch feature-x
| |
| o  changeset:   4:31b6f976956b
| |  summary:     Changeset2
| |
| o  changeset:   3:5cb34be9e777
| |  parent:      1:1cc843e7f4b5
| |  summary:     Changeset 1
| |
o |  changeset:   2:0a834fa43688
|/   summary:     Changeset C
|
o  changeset:   1:1cc843e7f4b5
|  summary:     Changeset B
|
o  changeset:   0:a9afb25eaede
   summary:     Changeset A

So you do this:

hg clone . ../cleanedrepo --rev 7

And you'll have the following, and you'll see that feature-x is indeed gone:

@    changeset:   5:00a7f69c8335
|\   tag:         tip
| |  parent:      4:31b6f976956b
| |  parent:      2:0a834fa43688
| |  summary:     merge
| |
| o  changeset:   4:31b6f976956b
| |  summary:     Changeset2
| |
| o  changeset:   3:5cb34be9e777
| |  parent:      1:1cc843e7f4b5
| |  summary:     Changeset 1
| |
o |  changeset:   2:0a834fa43688
|/   summary:     Changeset C
|
o  changeset:   1:1cc843e7f4b5
|  summary:     Changeset B
|
o  changeset:   0:a9afb25eaede
   summary:     Changeset A

I may have misunderstood what you wanted but please don't mod down, I took time reproducing your use case : )

弄潮 2024-08-27 22:08:19

奇怪的是,还没有人提出关闭功能分支的最可靠的方法......
您可以将合并提交与 --close-branch 标志结合起来(即提交修改的文件并同时关闭分支):

hg up feature-x
hg merge default
hg ci -m "Merge feature-x and close branch" --close-branch
hg branch default -f

所以,就是这样。转速表上没有一个额外的头。没有额外的承诺。

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):

hg up feature-x
hg merge default
hg ci -m "Merge feature-x and close branch" --close-branch
hg branch default -f

So, that is all. No one extra head on revgraph. No extra commit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文