2017-01-23 47 views
1

我一直試圖用另一個分支替換回購的master分支,但是我嘗試的每種方式都保留了不在其他分支中的提交。例如,另一個分支有121個提交,但在命令之後(兩個集都在下面)主顯示216個提交!如何完全替換master和其他所有提交的提交?

嘗試#1

#Replacing master with otherBranch branch 
git checkout otherBranch 
git merge -s ours master 
git checkout master 
git merge otherBranch 
git push 

嘗試#2

git checkout otherBranch 
git push [email protected]:remoteRepo :master 

#Also tried 
git checkout otherBranch 
git push [email protected]:remoteRepo +otherBranch:master 

的這些都具有相同的結果結束。

那麼我如何完全取代其他分支的主人?

回答

6

先爲您的主分支的備份:

git branch master_backup master 

然後執行以下操作刪除您當前的主,使otherBranch你的新主人:

git checkout master # switch to master branch 
git reset --hard otherBranch # dangerous command: make master point to where otherBranch is. You will loose work that was on master branch and not on otherBranch 
git push -f origin master # push this new master branch to origin; thereby crushing (-f) whatever was on master branch on origin 
相關問題