Date Tags svn / git

I wanted to move from an bulky svn repository containing several projects to smaller git repositories to allow for easy distribution of the files and tracking of the code. Of course, while doing that, I wanted to keep the file history... I could not use the classic filter-branch as I wanted to extract only a few files withing a directory.

So... First step is to checkgout the svn repository with git :

git svn clone $SVN_REPO_URL
cd $SVN_REPO_URL

or, if you have already done it, you can update the repository with

cd $SVN_REPO_URL
git svn rebase

then you would extract the history of the desired files into a patch file

git log --pretty=email --patch-with-stat --reverse --full-index --binary path/to/file* > /tmp/patch

This will generate a full patch to the file, from its creation to the last commit. The (old) path in the patch file are relative to the old svn structure. Thus one could change it to reflect the new desired path structure

sed -i -e 's/old\/path\///g' /tmp/patch

for example to remove all the path for the new repository

And after creating a new git repository, and within the repository, you can replay the file creation and modification with

mkdir $GIT_REPO
cd $GIT_REPO
git init .
git am < /tmp/patch

This will recreate the files, with their history, in the newly created git repository.