Skip to main content

Migration from SVN to GIT

Recently, I was tasked with migrating a Subversion (SVN) server to Git. I immediately started searching for direct import tools and found suggestions like svn2git and subGit.

However, these tools did not fully meet the requirements, so after further research, I found references to a Git command that allows cloning an SVN repository into Git while preserving the full history without additional configurations or external programs. The command in question is:

Add these triple backticks and “bash” before pasting in Hugo:

git svn clone http://svn/

This command sends a request to the SVN server and creates a new directory for the repository. It can accept parameters that can be passed to Git’s init and fetch commands.

However, cloning the repository without the commit logs and author mappings is not useful. To handle this, the following commands can be used.

First, run this command on the current SVN server to generate a file with all the commit authors:

svn log --xml | grep "<author>" | sort -u | perl -pe 's/.*>(.*?)<.*/$1 = /' | tee users.txt

This will create a users.txt file used as the authors mapping file during migration.

Next, run this command to clone the SVN repository into a local Git repository, including all commits and logs:

git svn clone --stdlayout --no-metadata --authors-file=users.txt svn://hostname/path dest_dir-tmp

Finally, set the remote origin for the new Git repository to push future changes:

git remote add origin git@server:user/project-name.git
git push origin --all

From this point on, it will be possible to synchronize the migrated repository with the Git server.