umläute
umläute

Reputation: 31274

`git rebase` entire branch-tree

I have two unrelated "parts" in my git repository, one of which contains merges:

  X---Y

        A---B---C
       /         \
  D---E---F---G---H

Now Y and D contain exactly the same filesm (think of the 2 parts as a single disjoint history)

I would like to rebase the entire second part (D..H) onto the first part, so i get something like

                A---B---C
               /         \
  X---Y---D---E---F---G---H

Unfortunately doing a simple git rebase only works for single branches, and will flatten the history and lose the branching/merging parts.

How can i rebase an entire "branch-tree"?

background

the code was originally developped using subversion. at some point I switched to git for implementing experimental features, but just started off the last state of the svn-repository (rather than doing a proper svn2git conversion). the git history includes branching, merging and things.

I would now like to switch over to git entirely, but would also like to combine both histories into a single one (including all merges).

Upvotes: 3

Views: 1113

Answers (1)

umläute
umläute

Reputation: 31274

it seems that the rebase command has some options to preserve branches (most important --preserve-merges:

git checkout d--h
git rebase --root  --preserve-merges --onto x--y

This will give me exactly what i wanted.

(As expected) it does not migrate any tags nor umerged branches. So to rebase the following D-based subtree (note that this contains two unmerged branches) onto Y,...

  X---Y

        A---B---C
       /
  D---E---F---G---H

..., you need multiple calls to git rebase:

git checkout branch-to-h
git rebase --root  --preserve-merges --onto x--y
git checkout branch-to-c
git rebase --root  --preserve-merges --onto x--y

which results in:

            A---B---C
           /
  X---Y---D---E---F---G---H

Upvotes: 2

Related Questions