交换主服务器和功能分支

时间:2013-06-19 19:47:51

标签: git branch

我们发现自己处于 master 有新功能工作的情况, feature1 (分支master)是稳定的master。我们怎样才能改变事物以便他们“交易场所”?即,feature1成为master,master成为 newfeaturebranch

我发现了几个类似的SO问题,但在这些情况下,他们不再关心旧的主提交。在这里,我们希望将当前的master保留为新的newfeaturebranch。

我想到了一种方法:

  1. 从当前母版创建 newfeaturebranch
  2. 的提交还原/删除回 feature1 的分支点。
  3. feature1 合并到 master
  4. 删除分支 feature1

3 个答案:

答案 0 :(得分:27)

您可以重命名分支:

git branch -m master newfeaturebranch
git branch -m feature1 master

答案 1 :(得分:0)

编辑:这篇文章是在你编辑你的问题之前写的,当你说你想简单地“交换场所”时。 如果您不需要保留名称,Poke的解决方案就足够了。


您需要第三个分支tmp,就像在编程中交换变量一样:

  • git checkout -b tmp master:启用从tmp
  • 创建的新master分支
  • git branch -D master:删除分支master
  • git checkout -b master feature1:从master
  • 重新创建feature1
  • git branch -D feature1:删除分支feature1
  • git checkout -b feature1 tmp:从newfeaturebranch重新创建tmp(这是master最开始的地方)

答案 2 :(得分:0)

我从Poke的解决方案开始,但是在推送之后,本地分支仍在跟踪旧的远程分支。要跟踪正确的分支,我只需要添加-u选项即可进行推送。

git branch -m master newfeaturebranch
git branch -m feature1 master

git push -uf origin master
git push -u origin newfeaturebranch

也可以分两步来完成:先推然后adjusting the correct branch to track

git push -f origin master
git push origin newfeaturebranch

git branch -u origin/master master
git branch -u origin/newfeaturebranch newfeaturebranch