Introduce merges in grafted Git history

211 views Asked by At

I'm currently importing an SVN repository into Git. The structure of the SVN repository is a bit messy so I'm having to convert it into three separate Git repositories and then merge them all together.

If these was a simple project with three parts to a single history, then I might just rebase them on top of the other, e.g.:

cd part3
git remote add -f part1 url_to_part1
git remote add -f part2 url_to_part2
git rebase part2/master
git rebase part1/master

However part3 in my example above contains dozens of tags and three branches. If parts 1 and 2 had been cleanly merged into master (well, trunk) within SVN, then I would do something like this to graft the branch into the history correctly. This has the benefit that all of the tags stay in place, unlike with a rebase.

But one of the branches has an orphaned commit that we would now like to merge into the history. Now if I try to fix the history with the graft, the changes from the orphaned commit are lost. In the example below, the merge X to C happened in SVN and so I can create the link with a graft. But I want to merge the orphaned commit O in between C and D, while preserving the tags on commits E, G etc.

A-B-C-[ ]-D-E-F-G-H-...  
 \ /  /
  X--O

Is there a way that I can specify the graph structure using something like the grafts file but then actually execute the implied merges? Or is there a filter-branch command that I should be using here?

1

There are 1 answers

2
Vampire On

git-svn is not the right tool for one-time conversions of repositories. It is a great tool if you want to use Git as frontend for an existing SVN server, but for one-time conversions you should not use git-svn, but svn2git which is much more suited for this use-case.

There are pleny tools called svn2git, the probably best one is the KDE one from https://github.com/svn-all-fast-export/svn2git. I strongly recommend using that svn2git tool. It is the best I know available out there and it is very flexible in what you can do with its rules files.

If you are not 100% about the history of your repository, svneverever from http://blog.hartwork.org/?p=763 is a great tool to investigate the history of an SVN repository when migrating it to Git.

You will be able to write the rules file in a way that you can convert your whole SVN repository in one very performant run to a proper Git repository.