guy labs guy labs

How to convert a SVN repository to GIT in Linux

Today we want to convert a SVN repository to a GIT repository. I did the same conversion at edorasware too. What you need is direct access (SSH access to the server where the SVN repository lies) to the SVN repository which you want to convert and have GIT installed on that server.

If you do this on a production SVN repository you need to tell all developers to stop committing while you are doing the conversion to prevent an inconsistent state of the GIT repository.

Let’s start by creating a dump of the SVN repository. (be sure you have enough disk space) Browse to the repository and execute the following command:

Now we have a dump of the repository which you can copy into a temporary folder where the conversion takes place.

Next we create an empty SVN repository and load the dump into this repository. Execute the following commands to do this:

This process leaves the original SVN repository intact such that you can go back to SVN if something happens while converting.

Next we need to download the svn2git tool which was used to convert the SVN repositories from the KDE project to GIT. Execute the following commands to clone the GIT repository:

Now we need to install some dependencies in order to make the svn2git executable. Install the libsvn-dev dependency and qt4. In ubuntu you would execute the following commands:

After the installation browse to the svn2git folder and execute the following commands to make the executable:

After this process you have the svn-all-fast-export executable inside the svn2git folder.

The next thing to do is to get a list of all users which did commits to that repository and create an author mapping which translates the SVN username to a GIT user. I did an LDAP export of all our users and created this file manually. I used the following perl script to export the needed values from LDAP: http://sourceforge.net/projects/ldap-csvexport. If you don’t have a LDAP you can execute the following command on the before created SVN repository:

Replace the ABSOLUTE-PATH-TO-SVN-REPO with the absolute path to the svn-repo created before.

Next create the authors-map.txt file which should have the following format:

Ok now we need to create a so called rules file. This rules file is used to tell the converter which repositories should be created and which branches should be tags etc. You can read more about these rule files here and see sample rules files here. For my conversion I used the following rules file:

As you see we don’t have a completely standard SVN layout because we have multiple projects in one SVN repository. But I’m sure you can adapt this to your needs.

Save the rules file as rules.txt.

So now we have all prerequisites to start the conversion. Now browse to the folder where you have the svn-repo SVN repository and execute the following command:

This should start the conversion and create a new test repository (in my case TEST) inside the current folder. After the conversion is done we can push the converted repository to GitHub, Stash or any other GIT hosting application such that we have a master repo. To do this we need to clone the repository and push it to the new origin. To do that execute the following commands:

Substitute the REPO-NAME with your repository name. (would be TEST in my case)

The last step we need to do is to create the .gitignore (which is the equivalent to the SVN ignores) file in the root directory of the cloned repository. To search for all SVN ignores in the old repository execute the following command inside the checked out repository:

With the list from SVN you can now create your .gitignore file with the help of this article from GitHub: https://help.github.com/articles/ignoring-files

I hope everything works with your conversions. As always feedback is welcome   🙂

Cheers,

Guy

17,447 total views, 2 views today

Tags: ,

Share Post :

4 Comments

  • ePirat
    November 21, 2014 9:11 AM at 9:11 AM http://a%20rel='nofollow'%20class='comment-reply-link'%20href='/2013/10/06/how-to-convert-a-svn-repository-to-git-in-linux/?replytocom=11205#respond'%20data-commentid=11205%20data-postid=405%20data-belowelement=comment-11205%20data-respondelement=respond%20aria-label='Reply%20to%20ePirat'%20-%20Reply/a

    Thank you very much, this is one of the best articles I could find about how to use svn2git. It really is such a great tool and I wasn’t aware of it because I only knew the other tool called svn2git (this ruby thing), which isn’t by far not as powerful as the KDE tool is.
    One thing I want to note is that there seems to be a not documented option that can be used in the ruleset file, which is the prefix, that allows you to specify a path which what the matching folder should be prefixed in your repository and this turned out to be so helpful for getting the svn externals that are at another spot at the repo to the right repository in the git repository.

    • guy
      November 21, 2014 12:36 PM at 12:36 PM http://a%20rel='nofollow'%20class='comment-reply-link'%20href='/2013/10/06/how-to-convert-a-svn-repository-to-git-in-linux/?replytocom=11206#respond'%20data-commentid=11206%20data-postid=405%20data-belowelement=comment-11206%20data-respondelement=respond%20aria-label='Reply%20to%20guy'%20-%20Reply/a

      Thanks for the nice comment about this article! Ok I didn’t know this command. Could you maybe make an example of how to use it? Then I can add that to the blog post. Because I don’t get the point where you say to get the SVN externals to the right GIT repository. You mean that with the prefix command you are able to retrieve the SVN externals into one GIT repository without the help of submodules etc.?

      • ePirat
        May 9, 2015 10:27 PM at 10:27 PM http://a%20rel='nofollow'%20class='comment-reply-link'%20href='/2013/10/06/how-to-convert-a-svn-repository-to-git-in-linux/?replytocom=12966#respond'%20data-commentid=12966%20data-postid=405%20data-belowelement=comment-12966%20data-respondelement=respond%20aria-label='Reply%20to%20ePirat'%20-%20Reply/a

        Well let’s say your repo structure has a folder /projectX and /foo and /bar.
        Let’s say those last two are as submodules in your projectX folder, there would be no easy way to get them in your project so that they are historically correct.

        But with prefix you can add those as special rules that make them end up in your repo. Probably you would want them in a subfolder, like /commons/, to achieve this, you would specify for the rules affecting them the prefix /commons/, so they end up in your projectX git repo in a folder called /commons/!

        If you have the SVN externals in another repository, you are out of luck, however. Of course this solution will also make them normal files, without any special handling, but that was fine for our usecase. We later removed them and added them as proper git submodules, but we wanted our history to remain intact so that when you clone an older version, you could still build them with the correct externals versions, that’s why we used this complicated way 😉

        • guy
          May 10, 2015 12:05 PM at 12:05 PM http://a%20rel='nofollow'%20class='comment-reply-link'%20href='/2013/10/06/how-to-convert-a-svn-repository-to-git-in-linux/?replytocom=12973#respond'%20data-commentid=12973%20data-postid=405%20data-belowelement=comment-12973%20data-respondelement=respond%20aria-label='Reply%20to%20guy'%20-%20Reply/a

          We removed all SVN externals and replaced them with project dependencies such that we do not need to merge them to GIT submodules. In my opinion the submodules in GIT are not that lightweight as in SVN and therefore we changed that. Thanks for sharing your experiences and nice that it worked out!

          Regards,

          Guy

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.