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

前端 未结 14 1487
梦毁少年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 04:13

    To do this without rewriting history (i.e. if you've already pushed the commits):

    git checkout master
    git revert 
    git checkout -b new-branch
    git cherry-pick 
    

    Both branches can then be pushed without force!

提交回复
热议问题