How to fix committing to the wrong Git branch?

前端 未结 11 1396
小鲜肉
小鲜肉 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 14:45

    So if your scenario is that you've committed to master but meant to commit to another-branch (which may or not may not already exist) but you haven't pushed yet, this is pretty easy to fix.

    // if your branch doesn't exist, then add the -b argument 
    git checkout -b another-branch
    git branch --force master origin/master
    

    Now all your commits to master will be on another-branch.

    Sourced with love from: http://haacked.com/archive/2015/06/29/git-migrate/

提交回复
热议问题