kjo
kjo

Reputation: 35331

How to do the "inverse" of `git rebase <some-branch>`?

In the history below, assume that commits B through E are completely independent from commits F through I.

                       br-1            master
  ⋯ ---A---B---C---D---E---F---G---H---I

How do I end up with a history that looks like this:

                       master
  ⋯ ---A---F'--G'--H'--I'
        \
         `-B---C---D---E
                       br-1

?

br-1 and master are meant to be branches. The prime in F' is meant to indicate that commit F' consists of exactly the same changes as those that went into commit F. Similarly for G', H', and I'.

(The desired operation is, effectively, the inverse of doing git rebase br-1 from master, starting from the second history shown above.)

Upvotes: 5

Views: 1559

Answers (2)

Per Johansson
Per Johansson

Reputation: 6887

Two options.

1)

git checkout master
git rebase --interactive A

Delete the lines for B through E

2)

git checkout master
git rebase --onto A E

Upvotes: 7

cdhowie
cdhowie

Reputation: 169353

With master checked out:

git rebase --onto A br-1 master

Upvotes: 3

Related Questions