Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Steps to migrate from SVN to GitLab

Steps to migrate from SVN to GitLab

This process worked for me. I take no responsibility for any damage or loss incurred as a result of following or not following these steps or, for that matter, anything else you might do or not do.

Setup

  • SVN is hosted at svn.domain.com.au.
  • SVN is accessible via http (other protocols should work).
  • GitLab is hosted at git.domain.com.au and:
    • A group is created with the namespace dev-team.
    • At least one user account is created, added to the group, and has an SSH key for the account being used for the migration (test using ssh git@git.domain.com.au).
    • The project favourite-project is created in the dev-team namespace.
  • The file users.txt contains the relevant user details, one user per line, of the form username = First Last <address@domain.com.au>, where username is the username given in SVN logs. (See first link in References section for details, in particular answer by user Casey).

Versions

  • subversion version 1.6.17 (r1128011)
  • git version 1.9.1
  • GitLab version 7.2.1 ff1633f
  • Ubuntu server 14.04

Commands

git svn clone --stdlayout --no-metadata -A users.txt http://svn.domain.com.au/svn/repository/favourite-project
cd favourite-project
git remote add gitlab git@git.domain.com.au:dev-team/favourite-project.git
git push --set-upstream gitlab master

That's it! Reload the project page in GitLab web UI and you will see all commits and files now listed.

Notes

  • If there are unknown users, the git svn clone command will stop, in which case, update users.txt, cd favourite-project and git svn fetch will continue from where it stopped.
  • The standard trunk-tags-branches layout for SVN repository is required.
  • The SVN URL given to the git svn clone command stops at the level immediately above trunk/, tags/ and branches/.
  • The git svn clone command produces a lot of output, including some warnings at the top; I ignored the warnings.

References

@leftclickben

This comment has been minimized.

Copy link
Owner Author

leftclickben commented Sep 14, 2014

This also works for github, just ensure that when creating the project, you don't tick any options like "initialise with README" or "license", or you will need to rebase and/or --force the push.

@cbscd

This comment has been minimized.

Copy link

cbscd commented Dec 1, 2014

Hi,
Will this migrate svn history to git?
and do you know what happens if some users no longer exist in svn? what can I do in these cases?
Thanks

@weismannweb

This comment has been minimized.

Copy link

weismannweb commented Jan 12, 2015

I think the instruction to create users.txt would be useful to add first in these instructions instead of just referencing another link to it:

Here is what I used....

From the root of your local Subversion checkout, run this command:

svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > users.txt

Then edit the users.txt file to add the emails for the users and continue with the git svn clone command.

@adithyank

This comment has been minimized.

Copy link

adithyank commented Jan 14, 2015

Will this migrate svn history to git, so that I can see the logs of the commits I did when it was in svn?

@leftclickben

This comment has been minimized.

Copy link
Owner Author

leftclickben commented Jan 21, 2015

@cbscd @adinthyank Yes, this will migrate the repository with the full history, commit comments, etc, as opposed to just the current state of the repository.

@leftclickben

This comment has been minimized.

Copy link
Owner Author

leftclickben commented Jan 21, 2015

@cbscd The users.txt file should contain an entry for all of the users mentioned in the SVN history. It doesn't matter whether the user is currently able to access the repository, all that matters is that they are listed in the history. If there is a user in the SVN history that isn't represented in the users.txt file, the process will fail, but you can update the users.txt file with the missing user and start again.

@leftclickben

This comment has been minimized.

Copy link
Owner Author

leftclickben commented Jan 21, 2015

@weismannweb Thanks for that, it certainly beats the trial-and-error method that I used. In my case, I had less than a dozen users all up, but your method would be excellent especially for repos with a lot more users.

@ghost

This comment has been minimized.

Copy link

ghost commented Feb 23, 2015

How can I push tags from the svn repository? I can see them created in the new repository under \refs\remotes\tags\ but there isn't any tag shown in gitlab.

@michabbb

This comment has been minimized.

Copy link

michabbb commented Apr 4, 2015

Here's another well documented Tutorial

@ChristianLutz

This comment has been minimized.

Copy link

ChristianLutz commented Jul 29, 2016

Also, there is an official migration documentation for gitlab.

@docdawning

This comment has been minimized.

Copy link

docdawning commented Sep 2, 2016

Props. Thanks a lot for this. I've used it with fairly satisfying success. Muchas mcfrickken gracias! (specifically, I followed the gitlab docs for svn -> git -> gitlab first, then I used this to get my tickets & milestones

@nissaba

This comment has been minimized.

Copy link

nissaba commented Sep 22, 2016

I got a empty repo after a very long list of files printed to the screen ending with this

Found possible branch point: svn://xxx.xxx.xxx.xxx/ios/MobileUniversal/trunk => svn://xxx.xxx.xxx.xxx/ios/MobileUniversal/branches/mantis681_jfwork, 3246
Use of uninitialized value $u in substitution (s///) at /Applications/Xcode.app/Contents/Developer/usr/share/git-core/perl/Git/SVN.pm line 101.
Use of uninitialized value $u in concatenation (.) or string at /Applications/Xcode.app/Contents/Developer/usr/share/git-core/perl/Git/SVN.pm line 101.
refs/remotes/origin/trunk: 'svn://xxx.xxx.xxx.xxx/ios' not found in ''

@vs

This comment has been minimized.

Copy link

vs commented Dec 1, 2016

It is also possible to create GitLab mirror of existing SVN project via SubGit, see instructions.

@ynotna87

This comment has been minimized.

Copy link

ynotna87 commented Jul 27, 2017

I am a noobie on this.

I get 'Can't create session' error when i want to access the svn that using https. What should i do ?

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.