How to fix committing to the wrong Git branch?

前端 未结 11 1395
小鲜肉
小鲜肉 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:52

    If you haven't yet pushed your changes, you can also do a soft reset:

    git reset --soft HEAD^
    

    This will revert the commit, but put the committed changes back into your index. Assuming the branches are relatively up-to-date with regard to each other, git will let you do a checkout into the other branch, whereupon you can simply commit:

    git checkout branch
    git commit
    

    The disadvantage is that you need to re-enter your commit message.

提交回复
热议问题