summaryrefslogtreecommitdiff
path: root/doc/workflow/importing/migrating_from_svn.md
blob: fc27a38f7350ff9da964ece33a454c6371a0c921 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Migrating from SVN to GitLab

Subversion (SVN) is a central version control system (VCS) while
Git is a distributed version control system. There are some major differences
between the two, for more information consult your favorite search engine.

## Overview

There are two approaches to SVN to Git migration:

1. [Git/SVN Mirror](#smooth-migration-with-a-gitsvn-mirror-using-subgit) which:
    - Makes the GitLab repository to mirror the SVN project.
    - Git and SVN repositories are kept in sync; you can use either one.  
    - Smoothens the migration process and allows to manage migration risks.

1. [Cut over migration](#cut-over-migration-with-svn2git) which:
     - Translates and imports the existing data and history from SVN to Git.
     - Is a fire and forget approach, good for smaller teams.

## Smooth migration with a Git/SVN mirror using SubGit

#### Prerequisites

Install Oracle JRE 1.8 or newer. On Debian-based Linux distributions follow this 
[instruction](http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html).

Download SubGit tool from [https://subgit.com/download/](https://subgit.com/download/)

Unpack downloaded SubGit zip archive to `/opt` directory, subgit will be available
at `/opt/subgit-VERSION/bin/subgit`

#### Configuration

In GitLab create new empty repository. In filesystem it will be located at 
`/var/opt/gitlab/git-data/repositories/USER/REPOS.git` path by default. 
For convenice, assign this path to a variable:

```
GIT_REPOS_PATH=/var/opt/gitlab/git-data/repositories/USER/REPOS.git
```

SubGit will keep this repository will be kept in sync with a remote SVN project.
For convenience, assign remote SVN project URL to a variable:

```
SVN_PROJECT_URL=http://svn.company.com/repos/project
```

Run SubGit to set up a Git/SVN mirror. Make sure `subgit` command is ran
on behalf of the same user that keeps ownership of GitLab Git repositories (`git` by default):

```
subgit configure --layout auto $SVN_PROJECT_URL $GIT_REPOS_PATH
```

Adjust authors and branches mappings, if necessary:

```
edit $GIT_REPOS_PATH/subgit/authors.txt
edit $GIT_REPOS_PATH/subgit/config
```

For more information regarding SubGit configuration options, refer to 
[documentation](https://subgit.com/documentation.html) at SubGit web site.

#### Initial translation

Run `subgit` to perform initial translation of existing SVN revisions into
Git repository:

```
subgit install $GIT_REPOS_PATH
```

After initial translation is completed, GitLab Git repository and SVN project
will be kept in sync by `subgit` - new Git commits will be translated to SVN
revisions and new SVN revisions will be translated to Git commits. Mirror works
transparently and does not require any special commands.

Would you prefer to perform one-time cut over migration with `subgit` use 
`import` command in place of `install`:

```
subgit import $GIT_REPOS_PATH
```

#### Licensing

Running SubGit in a mirror mode requires [registration](https://subgit.com/pricing.html). Registration is free for Open Source,
Academic and Startup projects.

We're currently working on deeper GitLab/SubGit intergation. You may track our
progress at [this issue](https://gitlab.com/gitlab-org/gitlab-ee/issues/990).

#### Support

For any questions related to SVN to GitLab migration with SubGit you can contact SubGit team at [support@subgit.com](mailto:support@subgit.com).

## Cut over migration with svn2git

If you are currently using an SVN repository, you can migrate the repository
to Git and GitLab. We recommend a hard cut over - run the migration command once
and then have all developers start using the new GitLab repository immediately.
Otherwise, it's hard to keep changing in sync in both directions. The conversion
process should be run on a local workstation.

Install `svn2git`. On all systems you can install as a Ruby gem if you already
have Ruby and Git installed.

```bash
sudo gem install svn2git
```

On Debian-based Linux distributions you can install the native packages:

```bash
sudo apt-get install git-core git-svn ruby
```

Optionally, prepare an authors file so `svn2git` can map SVN authors to Git authors.
If you choose not to create the authors file then commits will not be attributed
to the correct GitLab user. Some users may not consider this a big issue while
others will want to ensure they complete this step. If you choose to map authors
you will be required to map every author that is present on changes in the SVN
repository. If you don't, the conversion will fail and you will have to update
the author file accordingly. The following command will search through the
repository and output a list of authors.

```bash
svn log --quiet | grep -E "r[0-9]+ \| .+ \|" | cut -d'|' -f2 | sed 's/ //g' | sort | uniq
```

Use the output from the last command to construct the authors file.
Create a file called `authors.txt` and add one mapping per line.

```
janedoe = Jane Doe <janedoe@example.com>
johndoe = John Doe <johndoe@example.com>
```

If your SVN repository is in the standard format (trunk, branches, tags,
not nested) the conversion is simple. For a non-standard repository see
[svn2git documentation](https://github.com/nirvdrum/svn2git). The following
command will checkout the repository and do the conversion in the current
working directory. Be sure to create a new directory for each repository before
running the `svn2git` command. The conversion process will take some time.

```bash
svn2git https://svn.example.com/path/to/repo --authors /path/to/authors.txt
```

If your SVN repository requires a username and password add the
`--username <username>` and `--password <password` flags to the above command.
`svn2git` also supports excluding certain file paths, branches, tags, etc. See
[svn2git documentation](https://github.com/nirvdrum/svn2git) or run
`svn2git --help` for full documentation on all of the available options.

Create a new GitLab project, where you will eventually push your converted code.
Copy the SSH or HTTP(S) repository URL from the project page. Add the GitLab
repository as a Git remote and push all the changes. This will push all commits,
branches and tags.

```bash
git remote add origin git@gitlab.com:<group>/<project>.git
git push --all origin
git push --tags origin
```

## Contribute to this guide
We welcome all contributions that would expand this guide with instructions on
how to migrate from SVN and other version control systems.