Question

in GIT I have two branches in single repository - branch "A" and branch "B" (created from two folders in old SVN repository)

These branches are fully separated: They don't have common ancestor.

Each of these branches writes to different directory. For example: branch A writes only to directory "~/A" and branch B only to directory "~/B" (so there are no conflicts).

I would like to merge these two branches into single branch so it will look like single branch repository.

I have tried:

  • git merge - it will merge branches but in history there are both branches visible
  • git rebase - it works but commits are in wrong order - I would like to have commits ordered by time

Best way to do this is to take all changes from both branches, order it by time and one-by-one "replay" on some new branch. But I have no idea how to do it.

Thanks for answers!

Edit: This is how it looks like now (left-to-right by time):

Branch [A]:          A1----A2-------A3----A4-A5
Branch [B]:       B1----B2----B3-B4----B5

When using merge: 
                     A1----A2-------A3----A4-A5-\
                  B1----B2----B3-B4----B5--------\

When using rebase:
                     A1----A2-------A3----A4-A5-B1-B2-B3-B4-B5

What I need:
                  B1-A1-B2-A2-B3-B4-A3-B5-A4-A5 
Was it helpful?

Solution

You can use interactive rebase to reorder the commits into the desired order.

Interactive rebase lets you reorder your changes in a text file, and I suggest you write a bash script to prepare a list of you commits in the chronological order you require, eg:

pick b111111 B1
pick a111111 A1
pick a222222 B2
pick a222222 A2
pick b333333 B3
pick a333333 A3

...and then use that in the interactive rebase.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top