How to reset a branch to another branch with git?

前端 未结 5 1560
走了就别回头了
走了就别回头了 2020-12-12 12:14

let\'s say that we have an hotfixes branch which was created from master. we added commits to hotfixes, but those commits were not use

5条回答
  •  北海茫月
    2020-12-12 12:38

    this is how i did it with basic Git commands:

    git checkout hotfixes
    git reset --hard master
    git push --force origin hotfixes
    

    of course it's important to notify everyone working on hotfixes. most likely they will have to delete their local copy and start from a fresh one. an alternative, less invasive idea is to create a new branch:

    git checkout master
    git branch -tb hotfixes-2 # this creates branch `hotfixes-2` from a copy of `master`
    git push origin HEAD # this creates `hotfixes-2` on the remote server
    

提交回复
热议问题