我的Git项目中有一个项目分支和一个主分支。我想让项目分支成为主分支。但是,我想将旧的主分支保留为侧分支。我怎么能这样做?
电流:
----------- master
\______ project
我想要的是什么:
-------------------- project (new master branch)
\______ master (old)
答案 0 :(得分:1)
如果你想交换分支的名称,可能最简单的方法是:
git checkout --detach master # we put HEAD on master
git branch -f master project # move master to project (HEAD doesn't move)
git branch -f project # set project to HEAD
git checkout project
答案 1 :(得分:0)
// If you want to still retain the old master branch, then create a tag or new branch on that particular commit so you don't loose it:
git checkout master
git checkout -b master-old
// now if you want to go back to the old master branch you can checkout the master-old branch.
// from here you can simply reset the master branch to the project branch
git checkout master
git reset --hard project
git checkout master
// now your master branch and the project branch should be pointing to the same commit. you can continue developing on your master branch. you may even want to delete the project branch. up to you.
编辑:如果是公共回购,请不要这样做!
答案 2 :(得分:0)
您只需通过以下方式交换两个分支的分支名称:
git branch -m master project1 #change master branch name as project1
git branch -m project master #change project branch name as master
git branch -m project1 project #change project1 branch name as project
现在您的分支结构将如下所示:
-------------------- project (new master branch)
\______ master (old)