Git: move changes off of master branch

后端 未结 6 461
南旧
南旧 2021-02-03 20:53

Basic question but this happens to me all the time:

  • Make changes in a working-branch
  • Switch to master
  • git merg
6条回答
  •  南方客
    南方客 (楼主)
    2021-02-03 21:37

    If you already committed your changes to master but didn't push to anywhere...

    create a new branch for the last changes

    git checkout -b newfeat master
    

    replay all the changes (move the commits) on top of your working-branch branch

    git rebase --onto working-branch origin/master newfeat
    

    change to master branch and reset it to the state of the last push

    git checkout master
    git reset --hard origin/master
    

    At this point you have:

    • master pointing to the last pushed commit (origin/master)
    • working-branch never changed
    • a new newfeat branch that contains all the new commits and is ahead of working-branch.

提交回复
热议问题