Overwrite the master branch with a orphan branch in git

两盒软妹~` 提交于 2019-12-10 23:46:53

问题


I've created a new orphan branch with git checkout --orphan orphan-branch and made a lot of commits on that branch.

Now I want to replace the master branch with the newly created orphan-branch, all the files and the history of the master branch should be replaced by the files and the history of the orphan branch. What is the best way to do this?


回答1:


To replace the history and old file of the master branch you need to do a forced update on it.

git push origin +your_orphan_branch_name:master

Attention: This deletes the whole history on the remote repository for your branch master. But that what you intended to do...




回答2:


git branch -m master old-master // rename master to old-master locally

git branch -m orphan_branch master // rename orphan_branch to master locally

git push -f origin master // force-update master on remote



来源:https://stackoverflow.com/questions/37610157/overwrite-the-master-branch-with-a-orphan-branch-in-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!