Sackville-West Clan Wiki/ tech/ Git multi-repo migration

My school code repos have been in complete disarray for quite a while. I had most of it in some kind of revision control, but not reliably. Some was in git, some in darcs, some in svn from servers that weren't up anymore (school svn repos get taken down at the end of the quarter), and some was just sitting there... This is not a good situation.

So, in the spirit of spring cleaning, I set off to get it organized and into one repo for posterity's sake, I suppose. For the darcs and svn stuff, I decided to just blow away the history and add the stuff as is into a main git repo. Likewise, the unversioned stuff just needed to be git added. But for the various stuff that was already in git, the real problem was how to preserve the history and combine the various bits into one comprehensive bunch. Google provides several solutions, but this, which is better explained over on stackoverflow(second best response) really seemed the best.


The process is straightforward.

Move everything in the repo down one level in the file system. This way, src/school/foo/code.c becomes src/school/foo/foo/code.c

$ cd src/school/foo \
$ git filter-branch --index-filter \
'git ls-files -s | sed "s-\t-&foo/-" |
git update-index --index-info &&

Note the placement of foo in the above command. It should be replaced with your appropriate repo/directory name. You'll want a clean repo before you do this. I had to git reset --hard on some of the repos to get it to work.

Since I wanted everything to be merged into on repo at src/school, I did

$ cd ..
$ pwd
git init # note, you may do this in advance...
git pull foo

This move the contents of foo/foo up into foo/

And now blow away the old repo

$ rm -rf foo/foo foo/.git

And that's it. Repeat ad nauseum through the whole mess until done.

hide details...

It was really a pretty slick process and one worth remembering.