Mercurial:如果标签具有相同名称,如何切换到命名分支?

发布于 2024-10-13 04:41:07 字数 310 浏览 5 评论 0原文

我现在只是在玩 Mercurial,这可能永远不会成为问题,但我刚刚创建了一个存储库并添加了一些更改。我在某一点标记了它,然后在另一点创建了一个命名分支。标签和分支具有相同的名称。如果我执行 hg update name ,它会切换到标记版本。除了使用分支上的修订号之外,还有其他方法可以切换到分支吗?

我认为让我想到这一点的是,如果我们要编写一些脚本来自动构建特定修订版,我们只想指定一个标签或一个分支来构建。如果有人碰巧在标签和分支中使用相同的名称,那么我们在脚本获取正确修订版时就会遇到问题。唯一的解决方案是确保它们是唯一的,例如通过在名称前添加分支或标签?

I am just playing around with Mercurial at the moment and this may never come up as an issue, but I just created a repository and added some changes. I tagged it at one point then created a named branch at another. Both the tag and the branch have the same name. If I do hg update name it switches to the tagged version. Is there any way to switch to the branch other than by using a revision number on the branch?

I think what made me think about this was that if we were to write some scripts for automatically building a particular revision we would want to just specify either a tag or a branch to build from. If someone happened to use the same name in a tag and a branch then we would run into problems with the script getting the correct revisions. Is the only solution to this to make sure that they are unique, e.g. by pre-pending branch or tag to the name?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

小糖芽 2024-10-20 04:41:07

您可以通过解析 hg Branches 的输出来获取分支的最新版本。

考虑这种情况(一个分支和一个标签,都名为 popular):

$ hg tags
tip                            3:afb4026bfe32
popular                        1:cea974d8cfc4
$ hg branches
default                        3:afb4026bfe32
popular                        2:aa7ede2bb3f6

在类似 bash 的 shell 中,您会得到 branch popular 的尖端版本with:

$ hg branches | grep popular | awk -F ':' '{print $2}'

获取标签版本的工作方式类似,使用hg标签

现在您的脚本可以更新到有问题的分支/标签。

You get the tip revision of the branch by parsing the output of hg branches.

Consider this situation (a branch and a tag, both named popular):

$ hg tags
tip                            3:afb4026bfe32
popular                        1:cea974d8cfc4
$ hg branches
default                        3:afb4026bfe32
popular                        2:aa7ede2bb3f6

In bash-like shells, you get the tip revision of branch popular with:

$ hg branches | grep popular | awk -F ':' '{print $2}'

Getting the tag revision works similar, using hg tags.

Now your script is able to update to the branch/tag in question.

策马西风 2024-10-20 04:41:07

我认为你可以这样做:

hg update -r "limit(heads(branch(name)),1)"

它使用 revsets 功能(请参阅较新的 Mercurial 中的 hg help revsets )。

但如果是我的话,我会在殴打创建标签的人的头部和颈部后删除标签。

I think you could do it with:

hg update -r "limit(heads(branch(name)),1)"

which uses the revsets feature (see hg help revsets in a newer Mercurial).

But were it me I'd just delete the tag after beating the person who created it about the head and neck.

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