Git push to wrong branch

后端 未结 3 1096
悲&欢浪女
悲&欢浪女 2021-01-29 21:32

Working with git, after some \'commit\', and a couple of \'push\', I realized that am using the wrong branch !

Now I have to remove in some way my changes in wrong_branc

3条回答
  •  梦如初夏
    2021-01-29 22:03

    switch to that branch, check the git log and git revert those commits individually. Once you have done that, switch back to the desired branch and there you can then use git cherry-pick to pick specific commits from the git refs and merge it into the right branch.

    git checkout wrong_branch
    git revert commitsha1
    git revert commitsha2
    git checkout right_branch
    git cherry-pick commitsha1
    git cherry-pick commitsha2
    

    If the commits are grouped together and there are no commits pushed after your dirty commits, you can even use git reset to get that wrong branch to a state just before your commits and then follow that again using git cherry-pick to get your commits into the right branch.

    git checkout wrong_branch
    git reset commitsha3 #commit just before commitsha2
    git checkout right_branch
    git cherry-pick commitsha1
    git cherry-pick commitsha2
    

提交回复
热议问题