How to copy one branch to another regardless changes?

被刻印的时光 ゝ 提交于 2019-12-11 23:14:21

问题


I'm relatively new to Git; I usually use SVN. We have several branches. Because I have not used my branch for a while, the master branch is far ahead of my branch. How can I copy master branch to my branch regardless my changes (both locally and remotely)?


回答1:


suppose you want to remove all changes to your local branch and start again from master:

THE FAST METHOD

git checkout <your-branch>
git reset --hard master
git push -f origin <your-branch> #WARNING DANGEROUS COMMAND!!!!

THE LONG METHOD BUT MAYBE EASIER TO UNDERSTAND

go to master branch

git checkout master

now delete your branch, including all your work on that branch!

git branch -D <your-branch>

now recreate the branch on master, since you are still on master, you can just do:

git checkout -b <your-branch>

now push this to remote. You need to force pushing to remote, which is dangerous since you are changing your history on the remote (agreed, only for your-branch now)

git push -f origin <your-branch>


来源:https://stackoverflow.com/questions/34925739/how-to-copy-one-branch-to-another-regardless-changes

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