How to fix committing to the wrong Git branch?

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

    If you already pushed your changes, you will need to force your next push after resetting the HEAD.

    git reset --hard HEAD^
    git merge COMMIT_SHA1
    git push --force
    

    Warning: a hard reset will undo any uncommitted modifications in your working copy, while a force push will completely overwrite the state of the remote branch with the current state of the local branch.

    Just in case, on Windows (using the Windows command line, not Bash) it's actually four ^^^^ instead of one, so it's

    git reset --hard HEAD^^^^
    

提交回复
热议问题