git: how to move a branch's root two commits back

后端 未结 3 1512
闹比i
闹比i 2021-01-07 01:44

Let\'s say I have:

A - B - C - D - E - F  master
            \\ 
             \\- G - H  new feature branch

Now I realize that commits B an

3条回答
  •  我在风中等你
    2021-01-07 02:26

    You can do this with git rebase.

    First, let's rebase some commits from master:

    $ git checkout master
    $ git rebase --onto A C
    

    This will move all commits in the range from C to master (but not including C itself) onto the commit A.

    Now rebase feature but throw out commit D:

    $ git checkout feature
    $ git rebase --onto C D
    

    Similar to the previous command, this will move commits in the range from D to feature (not including D itself) onto C.

提交回复
热议问题