Move the most recent commit(s) to a new branch with Git

前端 未结 14 1241
梦毁少年i
梦毁少年i 2020-11-22 03:28

I\'d like to move the last several commits I\'ve committed to master to a new branch and take master back to before those commits were made. Unfortunately, my Git-fu is not

14条回答
  •  被撕碎了的回忆
    2020-11-22 03:54

    If you just need to move all your unpushed commits to a new branch, then you just need to,

    1. create a new branch from the current one :git branch new-branch-name

    2. push your new branch: git push origin new-branch-name

    3. revert your old(current) branch to the last pushed/stable state: git reset --hard origin/old-branch-name

    Some people also have other upstreams rather than origin, they should use appropriate upstream

提交回复
热议问题