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

前端 未结 14 1493
梦毁少年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:55

    How can I go from this

    A - B - C - D - E 
                    |
                    master
    

    to this?

    A - B - C - D - E 
        |           |
        master      newbranch
    

    With two commands

    • git branch -m master newbranch

    giving

    A - B - C - D - E 
                    |
                    newbranch
    

    and

    • git branch master B

    giving

    A - B - C - D - E
        |           |
        master      newbranch
    

提交回复
热议问题