0

Firstly, I imagine this is duplicate; I'm guessing there's a name for what I'm trying to do, but I can't find anything about it.

Imagine I have commits:

a1 -- a2 -- b1 -- b2 -- c1 -- c2

Where a, b, and c are branches. I'm trying to get the history so that it is:

     - b1 -- b2
   /
a1 -- a2 -- c1 -- c2

But if I try and rebase c onto a, I understandably get b as well.

Is there a good way to do this?

OliverRadini
  • 6,238
  • 1
  • 21
  • 46
  • Maybe the duplicate would be https://stackoverflow.com/questions/29914052/i-cant-understand-the-behaviour-of-git-rebase-onto. – mkrieger1 Jun 25 '19 at 09:04
  • Possible duplicate of [I can't understand the behaviour of git rebase --onto](https://stackoverflow.com/questions/29914052/i-cant-understand-the-behaviour-of-git-rebase-onto) – Chris Maes Jun 25 '19 at 09:16

1 Answers1

4

These are multiple steps. The basic operation is git rebase --onto <newbase> <oldbase> <tip> (where newbase and oldbase can be commit hashes or branch names, but tip should be a branch name).

I'm assuming you have branches b and c pointing to commits b2 and c2, respectively.

  1. git rebase --onto a2 b2 c

    Result:

              - b1 -- b2
            /
    a1 -- a2 -- c1 -- c2
    

    Note that b1 and b2 are still unchanged, I just had to move them up visually.

  2. git rebase --onto a1 a2 b

    Result:

        - b1 -- b2
      /
    a1 -- a2 -- c1 -- c2
    
mkrieger1
  • 19,194
  • 5
  • 54
  • 65