【问题标题】:Switch branches with default branch in mercurial在 mercurial 中使用默认分支切换分支
【发布时间】:2012-06-09 03:32:57
【问题描述】:

在我正在工作的一个 repo 中,我们有时创建了一个命名分支,以便在某个问题中尝试不同的方法。我们也继续在默认分支中工作。

既然命名分支已经成熟,可以这么说,我们想将该分支设为默认分支,并为(旧)默认分支指定一个不同的名称。

这样的事情可能吗?

我发现了这个问题,Mercurial: Can I rename a branch?,我可以成功重命名默认分支,但是之后当我尝试将命名分支重命名为默认时,它失败并出现错误

abort: a branch of the same name already exists

【问题讨论】:

    标签: mercurial branch rename


    【解决方案1】:

    是的,你可以。

    你需要关闭所有的分支,然后给他们需要的名字

    PS:好像你只需要在分支命令中添加-f 标志

    示例场景

    hg init
    echo "123" > file
    hg addremove
    hg commit -m "init default"
    
    hg branch new
    echo "new" >> file
    hg commit -m "init new"
    
    hg up default
    echo "default" >> file
    hg commit -m "default 2nd"
    hg commit --close-branch -m "close default"
    
    
    hg up new
    hg commit --close-branch -m "close new"
    
    hg branches # none
    
    hg log # see where to update if haven't saved id/hash somewhere
    
    hg up 3 # this changset was the "close default" one
    hg branch new -f
    hg commit -m "new new"
    
    hg up 4 # the changeset we closed "new" at
    hg branch default -f
    hg commit -m "new default"
    

    结果:

    >hg log -G
    o  changeset:   6:af87a53292cf
    |  tag:         tip
    |  parent:      4:700a73ac7cad
    |  user:        Ivan Kurnosov
    |  date:        Tue Jun 05 17:22:27 2012 +1200
    |  summary:     new default
    |
    | @  changeset:   5:4ee990605ba1
    | |  branch:      new
    | |  parent:      3:6ebccfc3e630
    | |  user:        "Ivan Kurnosov
    | |  date:        Tue Jun 05 17:18:01 2012 +1200
    | |  summary:     new new
    | |
    o |  changeset:   4:700a73ac7cad
    | |  branch:      new
    | |  parent:      1:4a149d3fe86e
    | |  user:        "Ivan Kurnosov
    | |  date:        Tue Jun 05 17:15:18 2012 +1200
    | |  summary:     close new
    | |
    | o  changeset:   3:6ebccfc3e630
    | |  user:        "Ivan Kurnosov
    | |  date:        Tue Jun 05 17:14:49 2012 +1200
    | |  summary:     close default
    | |
    | o  changeset:   2:92669a82423b
    | |  parent:      0:05657f61324b
    | |  user:        "Ivan Kurnosov
    | |  date:        Tue Jun 05 17:13:07 2012 +1200
    | |  summary:     default 2nd
    | |
    o |  changeset:   1:4a149d3fe86e
    |/   branch:      new
    |    user:        "Ivan Kurnosov
    |    date:        Tue Jun 05 17:12:30 2012 +1200
    |    summary:     init new
    |
    o  changeset:   0:05657f61324b
       user:        "Ivan Kurnosov
       date:        Tue Jun 05 17:11:51 2012 +1200
       summary:     init default
    

    【讨论】:

    • 举个简单的例子容易吗? :)
    • 太棒了。 -f 完成了这项工作。之后我还得做hg push --new-branch -f。也可以将其添加到您的示例中以完成。 :)
    • 附言。您在上面的屏幕截图中使用的是什么 GUI?
    • @George Kastrinis: 这是乌龟
    猜你喜欢
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 2012-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-21
    相关资源
    最近更新 更多