Research and Development

Migrating Bazaar Repository to Git

Over the years we have been using multiple version control systems and earlier this year we decided to start using Bazaar instead of Subversion because we were planning to start using Launchpad for our development. For various reasons we didn't start using Launchpad after all, but moved to Github, so now came time to migrate away one internal Bazaar repository to Git. I had seen various blog posts about bzr->git migrations, so I thought it'd be easy.

First I tried Tailor that should be able to migrate repositories between many different systems. It turned out that our bzr repository had quite a few commits that Tailor could not handle. These were related to some commits that had deleted directories and before that moved files elsewhere from those directories. For some reason the order of actions in the commits got lost and all git commands failed. I tried applying quite a few patches from mailing lists and updated various bits to get the migration half done before I had to give up.

After searching around it seemed like direct bzr->git migration would not be possible with other tools either, but both bzr and git seemed to support migration to/from svn, so I decided to try bzr->svn->git instead. After a few tries I was indeed successful in migrating the bzr repository to svn. Svn to git migration was an easy task after that as that seems to be well documented.

Somewhere in the process author names and commit timestamps got lost, but in this case those are not a huge problem, so this'll do it.

I'm sure there are better ways to do this, but here are the steps I had to take to get the repository migrated. I hope this helps others with the same problem.

First bzr, svn and bzr packages are needed on the system (testing was done on Ubuntu 10.04):

sudo apt-get install git-svn bzr-webdav bzr-svn bzr subversion

Create a local clone of the bzr repository and a temporary svn repository:

bzr clone https+webdav://host/bzr/path /tmp/bzrrepo

svnadmin create --fs-type fsfs /tmp/svnrepo

Next go to the .bzr directory of the checked out repository and push the repository to bzrimport branch under svn repository:

cd /tmp/bzrrepo/.bzr

bzr push file:///tmp/svnrepo/bzrimport

Finally create a git clone of the svn repository:

git svn clone file:///tmp/svnrepo/bzrimport /tmp/gitrepo

Finally there's a git repo under /tmp/gitrepo that has the individual commits with commit messages in it. Having the author data and timestamps would certainly be nice, so tips are welcome!

Veli-Matti Lintu

Comments