How to fix committing to the wrong Git branch?

前端 未结 11 1422
小鲜肉
小鲜肉 2020-11-29 14:09

I just made a perfectly good commit to the wrong branch. How do I undo the last commit in my master branch and then take those same changes and get them into my upgrade bran

11条回答
  •  半阙折子戏
    2020-11-29 15:01

    If the branch you wanted to apply your changes to already exists (branch develop, for example), follow the instructions that were provided by fotanus below, then:

    git checkout develop
    git rebase develop my_feature # applies changes to correct branch
    git checkout develop # 'cuz rebasing will leave you on my_feature
    git merge develop my_feature # will be a fast-forward
    git branch -d my_feature
    

    And obviously you could use tempbranch or any other branch name instead of my_feature if you wanted.

    Also, if applicable, delay the stash pop (apply) until after you've merged at your target branch.

提交回复
热议问题