简体   繁体   English

Mercurial:我可以重命名一个分支吗?

[英]Mercurial: Can I rename a branch?

We now have a "stiging" branch, where "staging" seems to be a far better semantic fit. 我们现在有一个“stiging”分支,其中“staging”似乎是一个更好的语义契合。 What's a good strategy for handling this? 处理这个问题的好策略是什么?

Update to the stiging branch and create a new branch off of it. 更新到stiging分支并stiging创建一个新分支。 Then close the old branch. 然后关闭旧分支。

In summary: 综上所述:

hg update stiging
hg branch staging
hg commit -m"Changing stiging branch to staging."
hg update stiging
hg commit --close-branch -m"This was a typo; use staging instead."
hg push --new-branch

For future readers: With the rebase extension, you can make a new branch with the same parent as stiging and move the entire branch history to it, like this: 对于未来的读者:使用rebase扩展,您可以使用与stiging相同的父级创建一个新分支,并将整个分支历史记录移动到它,如下所示:

hg update -r "parents(min(branch('stiging')))"
hg branch staging
hg commit
hg rebase --source "min(branch('stiging'))" --dest staging

This assumes that stiging has only one parent. 这假设stiging只有一个父母。 Of course you can just use explicit revision numbers instead. 当然,您可以使用显式修订号。

Note 1: If branch stiging includes merges with other branches, I think that this will preserve them, as long as staging and stiging have the same parent. 注1:如果分支stiging包括与其他分支的合并,我认为这将保留它们,只要stagingstiging具有相同的父级。 But I'd certainly double-check. 但我当然会仔细检查。

Note 2: Since this edits the history, the old branch won't simply disappear from cloned repositories (see the rebase documentation). 注意2:由于这会编辑历史记录,因此旧分支不会简单地从克隆的存储库中消失(请参阅rebase文档)。 Unless everyone can clone anew, it might not be a very practical solution for a large group. 除非每个人都能重新克隆,否则对于大型团队而言,这可能不是一个非常实用的解决方案。

Note3/Edit (courtesy of @JasonRCoombs): Now that phases are standard in mercurial, rebase will refuse to modify changesets that have already been pushed. 注3 /编辑(由@JasonRCoombs提供):现在这些阶段是mercurial中的标准, rebase将拒绝修改已经推送的变更集。 Either fool it by changing the phase back to draft (with hg phases ), or let the old branch stay where it is, and just make a properly named copy (eg, with `hg rebase --keep'). 要么通过将阶段更改回草稿(使用hg phases )来欺骗它,要么让旧分支保持原状,只需制作一个正确命名的副本(例如,使用`hg rebase --keep')。

If you have changesets on it, then you'll have to use the convert extension with a branchmap to rename it. 如果你有变更集,那么你必须使用带有分支图的转换扩展名来重命名它。 Everyone will then have to clone the new repo or strip off the old branch. 然后每个人都必须克隆新的回购或剥离旧的分支。

创建一个名为“staging”的新分支并忘记其他分支......

This modifies the history and is only for advanced Mercurial users. 这会修改历史记录,仅适用于高级Mercurial用户。 Don't do this if you don't know what that means. 如果您不知道这意味着什么,请不要这样做。

If stiging is local only, you can change it to staging with a combination of graft and strip . 如果仅仅局部搅拌,您可以使用移植条带的组合将其更改为分段。 Start by updating to the ancestor changeset where stiging had diverged. 首先更新到stiging已经分歧的祖先变更集。 Create the staging branch and graft each commit from stiging to staging. 创建暂存分支并将每个提交从stiging移植到staging。 Staging should now be a copy of stiging. 分段现在应该是stiging的副本。 Lastly, destroy stiging by stripping its first commit. 最后,通过剥离第一次提交来破坏stiging。

hg update {SHA-1 of the ancestor changeset}
hg branch staging
hg graft {first changeset in stiging} ... {stiging head-1} {stiging head}
hg strip {first changeset in stiging}
hg push --new-branch

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

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