36

具有以下分支结构:

                       master
                     /       \
                BranchA      BranchB

但它应该是:

                 master
                  /           
            BranchA        
               /
         BranchB

谁能建议如何将 BranchB 重新挂为 BranchA 的孩子?

4

3 回答 3

45

你想使用rebase。签出 BranchB 后,执行

git rebase BranchA
于 2012-11-05T15:47:25.973 回答
7
git checkout branchB; git rebase branchA;

会为你做这件事。请记住,如果这已被推到其他地方,您将搞砸历史。

于 2012-11-05T15:49:11.600 回答
1

I suggest using git rebase -i(interactive mode) to edit the whole history, which commit you want as the starting point of new branch rebase, the commit message, etc.

In your case, if you desired situation is:

             master
              /           
        BranchA        
           /
     BranchB

but on branchA you already have some commits:

             master
              /           
        BranchA
           |
        commit A1
           |
        commit A2

You may want to choose the A1 as starting point of branchB, not A2(the latest, where the HEAD of A is), then git rebase -i can help.

于 2018-08-15T21:13:28.940 回答