Max Romantschuk's weblog – December 2009 archive

Importing several CVS modules into a single Git repository

Tuesday 29th of December, 2009 - 14:26 – Permalink

A lot of projects are migrating to the Git version control system these days, and I found myself in a similar situation at work a while back. In my case I needed to go from CVS to Git. There is a command for this, git-cvsimport, but it only imports a single CVS module into a single Git repository.

I needed to import multiple CVS modules to a single Git repository, with the former modules being subdirectories in the new Git repo. There were a lot of instructions on how to do this available, but no real complete script for the job, so I made one: git-cvsmod2subdir.sh

The script works by taking a list of CVS modules to be imported as a space-separated list. It then imports each module as a temporary repository, rewrites history in that repository to make it seem like the modules contents was always in that subdirectory. Finally it merges the temporary repository with the target repository you're importing into. The script is designed to be ran in the root of a Git repo, and assumes you want your modules as top level subdirectories.

Branches aren't really properly handled, (we didn't have any as they are, um, painful in CVS...) but if you only need your CVS head with history this should do. The script is designed to be ran once, incremental updates aren't handled. (We had no need, and doing it while rewriting history would have been tricky to say the least.)

Thanks to everyone else contributing with useful Git documentation on the web. I my case the work on merging repositories by Zrajm and more of the same by Mathias Biilmann was a great help in understanding how to glue necessary pieces together.