Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

git-rebase

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.)

like image 432
kjo Avatar asked Jan 10 '23 22:01

kjo


2 Answers

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
like image 199
Per Johansson Avatar answered Jan 19 '23 04:01

Per Johansson


With master checked out:

git rebase --onto A br-1 master
like image 21
cdhowie Avatar answered Jan 19 '23 04:01

cdhowie