How to move the current working branch to master branch in git

后端 未结 10 1020
挽巷
挽巷 2020-12-13 00:13

I have currently one of the project it contain more branches. master branch not yet merger long time. So i want switched to master with latest code.

Can you please g

10条回答
  •  隐瞒了意图╮
    2020-12-13 00:46

    Firstly, I would try just merging it to master and seeing if there really are lots of conflicts - git's merging is great at only marking genuine conflicts. If you make sure that your git status is clean before you start, and you find that there are too many conflicts to deal with, you can just go back with:

    git reset --merge
    

    However, if you just want to make your current master the same as your other branch, you could do that with:

    git checkout master
    git reset --hard other-branch
    

    However, that's generally a bad idea since:

    1. You're throwing away all the work on your master branch. Perhaps you might want that history later? (You could always "back up" your master branch with git branch old-master master beforehand.)
    2. You're rewriting the history of the master branch, so if you've ever shared this branch with anyone the results will be confusing for both of you.
    3. git reset --hard should always be used with caution, since it will throw away all uncommitted changes you have.

提交回复
热议问题