Switching from SVN
local graph
Chapter 7 — Switching from SVN
Section titled “Chapter 7 — Switching from SVN”The shortcomings of CVS have led to the development of other systems, with one of the most well-known being Apache Subversion (SVN). In addition to the improvements it has brought, it was specially ensured that is has high compatibility with CVS. It is also open source licensed (with an Apache license, not GNU). It was started in 2000 by Collabnet Inc., but changed to an Apache project in 2009. You can find it at https://subversion.apache.org.
In this chapter, will we cover the following topics:
- The difference between SVN and Git
- Mirroring SVN with GIT
- Using svn2git to migrate in one cut
To follow along with the instructions in this chapter, please download this book’s GitHub repository, along with the examples from https://github.com/PacktPublishing/Mastering-GitLab-12/tree/master/Chapter07.
Some example will be executed on macOS and some on Debian 10.
The other requirements for this chapter are as follows:
- Git: http://git-scm.org
- SVN: https://subversion.apache.org/packages.html
- Git LFS: https://git-lfs.github.com
- SubGit: https://subgit.com
- svn2git: https://github.com/nirvdrum/svn2git
Like CVS, the biggest difference between Git and SVN is that SVN follows a centralized architecture, while Git uses a distributed network. There is one SVN server, and as a client you communicate your changes with it. This in different to Git, where there can be many local copies, and one copy can reside on a central server. This architecture is depicted as follows:

With Git, there are several options to choose from regarding protocol and network settings. Most importantly, you have the choice to communicate with remotes over SSH or HTTP. Using SSH, you wrap Git commands, possibly using certificate authentication, and with HTTP, you implement Git actions using WebDAV and basic HTTP authentication**.**
SVN has a networking layer that is abstracted, which means that clients exhibit the same behavior, no matter what sort of server they are operating against.
There are several different server options available, as follows:
- The svnserver server:This one is easy to set up, does not need system accounts on a server, and is faster than WebDAV (which extends the HTTP protocol with filesystem access). One big disadvantage is that communication using this server is unencrypted by default.
- svnserver through SSH: This has all the advantages we mentioned previously, but is protected with SSH encryption. It works by tunneling the svnserver traffic through an SSH session.
- The Apache web server with module dav_svn:In this situation, all traffic on the network layer is carried out over HTTP. The famous Apache web server has support for WebDAV operations, and there is a specific Apache module that handles SVN traffic (dav_svn). It is noticeably slower because of the overhead in the HTTP protocol, but is had the added bonus that repositories are browse-able through a web browser.
Besides their infrastructural difference, there are also several differences between your local SVN/Git client.
With SVN, you can set up your server to grant or deny permissions to users. You can even define finer-grained access rules based on paths. All of this is configured in a central location. With Git running on your client, there is no access control by default. Your server implementation or central repository that’s running Git must do that for you. GitLab has this functionality.
The repository’s change history is kept centrally on the server in the SVN world, and to change it you need to gain access to this central place.
Because Git is a distributed versioning system, every developer can make changes to any part of their local repository history. Although pushing a changed history is heavily discouraged, it is possible. This can wreak havoc if other developers are depending on particular changes.
For Git users, the complete history of a repository is saved locally and updated from and to remotes, so there is always a local copy.
Making regular backups is smart to do with both Git and SVN. Even with a central server and several distributed copies, you need to stay in sync to keep all the data available.
One of the things SVN can do compared to Git is that you can check out parts of the repository. In Git, the repository can only be cloned as a whole.
In Git, every object has a unique ID, that is, a SHA-1; for instance, 921103db8259eb9de72f42db8b939895f5651422.
This makes it easier to reference. You can also use a shortened version (921103d):
$ git rev-parse --short 921103db8259eb9de72f42db8b939895f5651422921103dIn SVN, a file is always the newest version. To reference changes to a file, you need to use revisions. That revision points to the whole repository.
SVN working directories contain two copies of each file, which is why Git repositories are generally much smaller – they only contain one copy. A directory with a cloned Git repository contains a small index file with approximately 100 bytes of index data per tracked file.
If a project has a lot of files, the difference in size between SVN and Git can become quite large! A thing most people don’t realize is that SVN can track empty directories, while Git cannot! Only file contents are tracked by Git, so empty directories will not show! The following diagram shows the way SVN handles changes:

Git, on the other hand, uses the graph model, which is as follows:

As we can see, the difference in size and the ways of referencing between SVN and Git is very large!
Both Git and SVN support the use of branches. However, for SVN, branches are part of a possible workflow and style, while for Git the use of branches is built into the command palette and standard way of working.
One of the major disadvantages of SVN is the way of branching and merging. It can take a long time if you have large repositories. If you create a new branch in SVN, you create a completely new directory within the repository, which means there is repetition in that structure. When the branch is ready or no longer needed, you commit back to the trunk.
A big technical difference between Git and SVN versions before 1.5 is that Git used three-way merges as standard, while SVN used two-way merges. It couldn’t perform three-way merges because it didn’t store merge information. Git, by using its graph database, can check where the code bases share a common state and then merge from the diversion point, which is then technically a three-way merge. In the latest version of SVN, this is also incorporated because the meta information about branches and merges is kept after merging. Unfortunately, the basic problem still exists – a branch is a full copy (not a reference).
At the same time, there can be changes on the trunk already. Your version of it won’t have the changes that are in the branches of developers. This means that you could have conflicting changes, files, or structures that are missing in your branch.
The main reason developers like Git so much is the power of the branching model. Comparing it to the many repetitions in SVN, Git only creates references to a specific commit, so there’s less repetition and less waste of space and I/O. Instantiating the reference by creation, deletion, or changing a branch will not affect the commits. Want to try something? Fix a bug quickly? Just create a branch, edit files, and push the commits to the central repository, then delete the branch. Create them lightheartedly!
Speed is often recited as the main advantage Git has over SVN. This is not exactly the case when handling binary files. If developers checkout full repositories every time and they contain changing binary files, you lose this speed advantage.
In SVN, only the working tree and the latest changes are checked out to the local system. When many changes are made to binary files, checking them out in SVN takes less time than with Git.
Of course, there are workarounds for storing binary files in Git repositories, the most famous being Git LFS (https://git-lfs.github.com/). This is a solution that was developed by GitHub and is an extension to Git. With it, you store a pointer inside your repository instead of in a big binary file. Still, every developer action leads to a pile of changed history data. This is going to make operations perform slower.
GitLab also supports Git LFS operations. Depending on how you or your administrator configured GitLab, the location of LFS uploaded data can be on the GitLab server itself, or on shared server storage that’s connected to you GitLab server. Alternatively, it can be stored on an S3-compatible service.
You can install Git LFS on several platforms (https://github.com/git-lfs/git-lfs/wiki/Installation). The main requisite is that you have installed Git version 1.8.2 or higher.
Let’s try using git-lfs:
- We will try this on macOS and install it with brew:
$ brew install git-lfs ==> Downloading https://homebrew.bintray.com/bottles/git-lfs-2.6.1.high_sierra.bottle.tar.gz ==> Downloading from https://akamai.bintray.com/0d/0daf04ca0a32e208be0e6df07c42a1ab049a3e50c962b04ea650a626a97920bb?__gda__=exp=1545082825~hmac=321540978a32b9bda7e114cc68cdddb1c772d02d8c93ed919a0d04bff4075377&respo ######################################################################## 100.0% ==> Pouring git-lfs-2.6.1.high_sierra.bottle.tar.gz ==> Caveats- Update your Git configuration to finish the installation:
$ git lfs install$ git lfs install --system- When you have Git LFS installed, you need to enable the functionality for your local repository:
$ git lfs install Updated git hooks. Git LFS initialized.- Tell Git which kind of files you consider large. After this, add the .gitattributes file to the commit:
$ git lfs track "*.dmg" Tracking "*.dmg"$ git add .gitattributes- The next step it to just add and commit your changes:
$ git add .$ git commit -m "Testing lfs" [master eb9ed7c] Testing lfs 2 files changed, 4 insertions(+) create mode 100644 .gitattributes create mode 100644 OpenRA-release-20180923.dmg- Now, when you push the repository to the remote server, you will notice a different behavior. Git LFS is handling part of the upload:
$ git push Locking support detected on remote "origin". Consider enabling it with: $ git config lfs.https://gitlab.com/joustie/itsmyparty_gitlab.git/info/lfs.locksverify true Uploading LFS objects: 100% (1/1), 35 MB | 979 KB/s, done Counting objects: 4, done. Delta compression using up to 16 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (4/4), 487 bytes | 0 bytes/s, done. Total 4 (delta 1), reused 0 (delta 0) To gitlab.com:joustie/itsmyparty_gitlab.git 6b64bcc..eb9ed7c master -> masterSo, even with SVN handling files faster, if you use Git LFS, you get the same advantages.
If you compare Git LFS with SVN on a basic level, then SVN is faster when it comes to handling binary files. If you use additional Git LFS for Git, they perform approximately the same.
In order to mirror SVN with Git, we will use the SubGit tool (https://subgit.com/), which is maintained and sold by TMate software. You can download a version for your operating system or choose the basic one, which is a multiplatform Java binary. If you unzip the package you downloaded, the SubGit tool can be found in the bin directory.
SubGit should be set up on your Git server. It will scan the settings for the remote SVN repository you specify, then download SVN revisions and convert them into Git commits. SubGit keeps both repositories synchronized. When a user pushes a new commit to Git, SubGit converts and tries to update SVN. It also gets new revisions from SVN as soon as they appear. SVN and Git users see each other’s commits as if they were all working on the same versioning system. SubGit makes sure that possible conflicts don’t occur between the systems and maintains the integrity of the mirror.
Keep in mind that for this sync to work, your GitLab server should not use hashed storage. Hashed directory names are not very usable in this context.
Furthermore, the following examples will be executed on a Debian 10 machine, which is why the apt-get package manager is used.
Running SubGit in mirror mode requires that you register the software at TMate software. Registration is free for open source, academic, and start-up projects:
- First, create an empty project in GitLab:

- Then, open a Terminal on the machine where your GitLab instances are running and create the following environment variables. SVN_PROJECT_URL should contain a link to the SVN project you want to copy/convert/mirror:
$ export GIT_REPO_PATH=$HOME/git/pdf.git$ export SVN_PROJECT_URL=svn://svn.riscos.info/pdf/trunk/- Make sure that you have Java configured on the machine:
$ apt-get install openjdk-8-jdkReading package lists... DoneBuilding dependency treeReading state information... Done......Setting up openjdk-8-jdk:amd64 (8u191-b12-0ubuntu0.16.04.1)...- Now, we can start the first run of the SubGit tool, which configures everything in order for the mirroring or one-time migration to succeed (I have copied the subgit binary from the package to /opt/subgit/bin):
$ /opt/subgit/bin/subgit configure --layout auto $SVN_PROJECT_URL $GIT_REPO_PATH SubGit version 3.3.5 ('Bobique') build #4042
Configuring writable Git mirror of remote Subversion repository: Subversion repository URL : svn://svn.riscos.info/pdf Git repository location : /var/opt/gitlab/git-data/repositories/root/pdf.git
Git repository is served by GitLab, hooks will be installed into 'custom_hooks' directory.
Peg location detected: r35 trunk Fetching SVN history... Done. Growing trees... Done. Project origin detected: r1 trunk Building branches layouts... Done. Combing beards... Done. Generating SVN to Git mapping... Done.
CONFIGURATION SUCCESSFULTo complete SubGit installation and have it running continuously, do the following:
- Adjust Subversion to Git branch mapping if necessary in the following file:
/var/opt/gitlab/git-data/repositories/root/pdf.git/subgit/config- Define at least one Subversion credential in the default SubGit password file, as follows:
/var/opt/gitlab/git-data/repositories/root/pdf.git/subgit/passwdAlternatively, you can configure SSH or SSL credentials in the [auth] section of the following root:
/var/opt/gitlab/git-data/repositories/root/pdf.git/subgit/config- Optionally, add custom authors mapping to the authors.txt file(s) in the following file:
/var/opt/gitlab/git-data/repositories/root/pdf.git/subgit/authors.txt- Run the subgit install command:
$ subgit install /var/opt/gitlab/git-data/repositories/root/pdf.gitIf you query the process list, you will see that the SubGit daemon is running:
$ ps ax |grep subgit |grep -v grep 17314 ? Ssl 0:00 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -noverify -client -Djava.awt.headless=true -Djna.nosys=true -cp /var/opt/gitlab/git-data/repositories/root/pdf.git/subgit/lib/subgit-3.3.5_4042_fat.jar org.tmatesoft.translator.SubGitDaemon test --svn /var/opt/gitlab/git-data/repositories/root/pdf.git --limit 1544992584093If you view the project in GitLab directly after the installation done with SubGit, you will find that there is still nothing visible. This is because of caching the user interface. So far, we have done operations on the filesystem and we need to flush the Redis cache.
You can use the following command on the GitLab server to do this:
$ gitlab-rake cache:clearNow, the imported project should be visible:

We now have two source code repositories that are in sync. Sometimes, you only need one-way conversion, and this is what we will be covering in the next section.
You can also use the SubGit tool to do a one-time migration. You don’t need a license for this, and it’s free. Just download the tool and run it.
So, instead of using install, which enables synchronization, just use import as an argument:
$ /opt/subgit/bin/subgit import $GIT_REPO_PATH SubGit version 3.3.5 ('Bobique') build #4042
Translating Subversion revisions to Git commits...
Subversion revisions translated: 35. Total time: 9 seconds.
IMPORT SUCCESSFULAfter this has completed, you can refresh the cache to see the changes being reflected in the web UI.
A one-time conversion is an easy operation to perform compared to a sync, but there is another tool that can do this as well.
As you have seen with SubGit, it is possible to create a syncing solution between SVN and Git. In reality, most of the time, when you want to migrate to a new system, you will want to do it in one go. It decreases the margin of error and is easier to reason about. So, when you do such a hard cut over, make your developers use the new repository. Setting up syncing will not help you migrate in the long run. In comparison to SubGit, you can use your own workstation to do the conversion.
You can use a tool such as svn2git (https://github.com/nirvdrum/svn2git) to do a conversion in one step. On your workstation, you can install it as a Ruby Gem if you already have Ruby and Git installed:
$ sudo gem install svn2gitOn Debian-based Linux distributions, you can install the native packages:
$ sudo apt-get install git-core git-svn rubyIf you need the authors in your project to display correctly, you can make sure that mapping the authors from SVN to Git is performed correctly as part of the conversion. It depends on whether you create an authors file or not. If you choose not to, then no mapping will be performed. In some situations, this can be an issue, while some users don’t care at all. If you want to map users, make sure you map every author in the SVN repository. Failing to do so will result in a failed conversion, and you will have to start again.
By using the following command, you will get a list of authors that are present in the repository. Run the following in the SVN source repository. I have done so on my workstation:
$ svn log --quiet | grep -E "r[0-9]+ \| .+ \|" | cut -d'|' -f2 | sed 's/ //g' | sort | uniq cgransden peterIn this case, there are only two authors. Use the following output to create the authors.txt file and map authors line by line:
cgransden = cgransden <[email protected]> peter = peter <[email protected]>The repository we are converting has a reasonable default structure. It has a trunk, branches, and tags. If your SVN repositories are more complicated, you have to use more options. You can find these in the svn2git documentation on the home page shown earlier, or use svn2git —help.
Make sure that you run the svn2git conversion command in an empty directory.
The default format of the svn2git command line is https://svn.example.com/path/to/repo —authors /path/to/authors.txt.
In my example, we are not changing authors, so we’ll leave them out. If your SVN repository is protected by a username and password, you can add the —username ‘password’ and —password ‘password’ options as well:
$ svn2git svn://svn.riscos.info/pdf Initialized empty Git repository in /Users/joostevertse/svn/pdf.git/.git/ r1 = 154856522ddf7c81f34dc80b11a41b963dcc2c13 (refs/remotes/svn/trunk) A !PDF/!sprites22,ff9 A !PDF/Documents/Help.html,faf A !PDF/Documents/Licences/Copying A !PDF/Documents/Licences/BSDLicence A !PDF/Documents/Licences/README...The next step is to finish the conversion by pushing your migrated repository to GitLab. It’s best to create an empty project in GitLab and fetch the projects HTTP or SSH location. Then, you can add it as a remote to your local repository and push it. This will contain all the commits and branches.
When the conversion is complete, you can import the project into GitLab by creating a new remote locally and push the repository:
$ git push --all origin Counting objects: 1009, done. Delta compression using up to 16 threads. Compressing objects: 100% (414/414), done. Writing objects: 100% (1009/1009), 1.39 MiB | 0 bytes/s, done. Total 1009 (delta 591), reused 1009 (delta 591) remote: Resolving deltas: 100% (591/591), done. To https://gitlab.joustie.nl:8443/root/pdf.git * [new branch] master -> masterIf you have tags, don’t forget to push them, too:
$ git push --tags originEverything up-to-dateThis finalizes the conversion using svn2git, the second tool that you can use to perform a one-off migration of SVN to Git.
In this chapter, we started by tracing the origins of SVN and why it rose to popularity. Afterwards, we made a comparison between SVN and Git on certain aspects that are relevant for versioning systems, such as architecture, branching methods, and how to deal with binary files.
The second part of this chapter deals with ways to migrate SVN projects to Git. The first tool we discussed was SubGit. It is capable not only of migration projects from SVN to Git, but can also act as a proxy and let both repositories coexist. The second tool we talked about was svn2git, which does a migration in one cut. The other notable difference between these tools is that SubGit is installed on your GitLab server, while svn2git can be run from your workstation.
In the next chapter, we will take a look at another type of source control system. This one is created by Microsoft and not open source.
- What is the home page of the SVN project?
- What is the biggest difference between SVN and Git?
- Name the three different ways to run a SVN server.
- With SVN, where is the history of a project saved?
- Git uses SHAs, but what does SVN use?
- What type of merge did SVN versions before 1.5 perform?
- What version of Git is needed for Git LFS?
- Name two ways that GitLab implements LFS as storage backend.
- What two mechanisms does SubGit support for migration?
- When you use svn2git, what is the last step of migrating to GitLab?