简体   繁体   English

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

[英]Mercurial: How to switch to a named branch if a tag has the same 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. 我现在正在玩Mercurial,这可能永远不会成为一个问题,但我只是创建了一个存储库并添加了一些更改。 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. 如果我做hg update name它会切换到标记版本。 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, eg by pre-pending branch or tag to the name? 是唯一的解决方案,以确保它们是唯一的,例如通过预先挂起的分支或标记名称?

You get the tip revision of the branch by parsing the output of hg branches . 通过解析hg branches的输出,您可以获得分支的最新修订。

Consider this situation (a branch and a tag, both named popular ): 考虑这种情况(一个分支和一个标签,都命名为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: 在类似bash的shell中,你得到的分支的尖端修订版popular

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

Getting the tag revision works similar, using hg tags . 使用hg tags获取标记修订的工作方式类似。

Now your script is able to update to the branch/tag in question. 现在,您的脚本可以更新到相关的分支/标记。

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). 它使用revsets功能(请参阅较新的Mercurial中的hg help revsets )。

But were it me I'd just delete the tag after beating the person who created it about the head and neck. 但是我是这样的,我只是在击败创造头部和颈部的人之后删除标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM