Chris
Chris

Reputation: 193

Git rebase back and forth between two branches

First I have the following 3 branches.

1---2 (A)
    |\
    | 3 (B)
     \
      4 (C)

In order to rebase (C) on (B), I do:

git checkout C
git rebase B

and the result is:

1---2 (A)
     \
      3 (B)
       \
        4 (C)

Let's say I have committed something in (C) so I have:

1---2 (A)
     \
      3 (B)
       \
        4---5 (C)

Now I want to rebase (C) back on (A) so I would have:

1---2 (A)
    |\
    | 3 (B)
     \
      4---5 (C)

How do you do this ?

Upvotes: 0

Views: 145

Answers (1)

C-Otto
C-Otto

Reputation: 5853

In the last step you don't want to do a standard rebase, as you want to drop 3 from the history of C. In this case you can use interactive rebase:

git checkout C
git rebase -i A

In the resulting editor window find the line for commit 3, remove it, save the file and close the editor. git will then rebase 4 and 5 onto A (2) while ignoring 3.

Upvotes: 1

Related Questions