1625

I read the Git manual, FAQ, Git - SVN crash course, etc. and they all explain this and that, but nowhere can you find a simple instruction like:

SVN repository in: svn://myserver/path/to/svn/repos

Git repository in: git://myserver/path/to/git/repos

git-do-the-magic-svn-import-with-history \
svn://myserver/path/to/svn/repos \
git://myserver/path/to/git/repos

I don't expect it to be that simple, and I don't expect it to be a single command. But I do expect it not to try to explain anything - just to say what steps to take given this example.

5

34 Answers 34

1663

Create a users file (i.e. users.txt) for mapping SVN users to Git:

user1 = First Last Name <[email protected]>
user2 = First Last Name <[email protected]>
...

You can use this one-liner to build a template from your existing SVN repository:

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

SVN will stop if it finds a missing SVN user, not in the file. But after that, you can update the file and pick up where you left off.

Now pull the SVN data from the repository:

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

This command will create a new Git repository in dest_dir-tmp and start pulling the SVN repository. Note that the "--stdlayout" flag implies you have the common "trunk/, branches/, tags/" SVN layout. If your layout differs, become familiar with --tags, --branches, --trunk options (in general git svn help).

All common protocols are allowed: svn://, http://, https://. The URL should target the base repository, something like http://svn.mycompany.com/myrepo/repository. The URL string must not include /trunk, /tag or /branches.

Note that after executing this command it very often looks like the operation is "hanging/frozen", and it's quite normal that it can be stuck for a long time after initializing the new repository. Eventually, you will then see log messages which indicate that it's migrating.

Also note that if you omit the --no-metadata flag, Git will append information about the corresponding SVN revision to the commit message (i.e. git-svn-id: svn://svn.mycompany.com/myrepo/<branchname/trunk>@<RevisionNumber> <Repository UUID>)

If a user name is not found, update your users.txt file then:

cd dest_dir-tmp
git svn fetch

You might have to repeat that last command several times, if you have a large project until all of the Subversion commits have been fetched:

git svn fetch

When completed, Git will checkout the SVN trunk into a new branch. Any other branches are set up as remotes. You can view the other SVN branches with:

git branch -r

If you want to keep other remote branches in your repository, you want to create a local branch for each one manually. (Skip trunk/master.) If you don't do this, the branches won't get cloned in the final step.

git checkout -b local_branch remote_branch
# It's OK if local_branch and remote_branch are the same names

Tags are imported as branches. You have to create a local branch, make a tag and delete the branch to have them as tags in Git. To do it with tag "v1":

git checkout -b tag_v1 remotes/tags/v1
git checkout master
git tag v1 tag_v1
git branch -D tag_v1

Clone your GIT-SVN repository into a clean Git repository:

git clone dest_dir-tmp dest_dir
rm -rf dest_dir-tmp
cd dest_dir

The local branches that you created earlier from remote branches will only have been copied as remote branches into the newly cloned repository. (Skip trunk/master.) For each branch you want to keep:

git checkout -b local_branch origin/remote_branch

Finally, remove the remote from your clean Git repository that points to the now-deleted temporary repository:

git remote rm origin
33
  • 38
    This blog post by Eelke is a great cross-reference for the answer above. blokspeed.net/blog/2010/09/converting-from-subversion-to-git
    – kgriffs
    Mar 6, 2012 at 16:13
  • 4
    This is 99% awesome, following these steps, I got everything in order except branches: after the final step, they were remote only (and as such disappeared when I did the command: git remote rm origin)
    – Mick F
    Mar 29, 2012 at 9:22
  • 5
    GitHub has a very convenient step-by-step: github.com/nirvdrum/svn2git#readme Oct 17, 2012 at 14:11
  • 12
    For those under Windows, I created a PowerShell script based on this method: gist.github.com/Gimly/90df046dc38181bb18de
    – Gimly
    Jun 16, 2014 at 9:42
  • 9
    Warning for large repos with a lot of history, this is slow and tedius. I gave up trying to migrate all the old branches and simply migrated trunk.
    – Jess
    Sep 4, 2015 at 13:01
552

Magic:

$ git svn clone http://svn/repo/here/trunk

Git and SVN operate very differently. You need to learn Git, and if you want to track changes from SVN upstream, you need to learn git-svn. The git-svn main page has a good examples section:

$ git svn --help
9
  • 147
    The answer from @Casey answers the original question much better. Feb 26, 2012 at 14:58
  • 3
    Will this keep the branches and everything? or just clone the trunk?
    – Heetola
    Sep 25, 2012 at 19:16
  • 7
    @Eildosa: This will just clone the trunk. See Casey's answer for an alternative.
    – sleske
    Aug 10, 2013 at 13:30
  • 4
    @DougWilson but I can't see any Casey's answer here. Is it the answer below with 13 authors that begins with "Create a users file"? Aug 5, 2016 at 8:50
  • 85
    For anyone else who's wondering which is "Casey's answer" which is referenced in lots of comments around here, it's this one (Casey changed his nick to cmcginty). Oct 5, 2016 at 10:35
206

Cleanly Migrate Your Subversion Repository To a Git Repository. First you have to create a file that maps your Subversion commit author names to Git commiters, say ~/authors.txt:

jmaddox = Jon Maddox <[email protected]>
bigpappa = Brian Biggs <[email protected]>

Then you can download the Subversion data into a Git repository:

mkdir repo && cd repo
git svn init http://subversion/repo --no-metadata
git config svn.authorsfile ~/authors.txt
git svn fetch

If you’re on a Mac, you can get git-svn from MacPorts by installing git-core +svn.

If your subversion repository is on the same machine as your desired git repository, then you can use this syntax for the init step, otherwise all the same:

git svn init file:///home/user/repoName --no-metadata
6
  • 1
    As I commented on the other answer, I had to remove the spaces around = in users.txt because the import was aborting and I was getting an empty repository. Jan 31, 2013 at 3:08
  • 8
    Ah! Simple and effective explanation. In my case file:/// refused to work, just I used svnserve.exe --daemon and then used svn://localhost/home/user/repo instead. Jun 5, 2013 at 12:13
  • On my Mac running Mountain Lion, git svn wouldn't work until I went into Xcode and installed the Command Line Tools found in the Downloads tab of the Preferences pane. Alternatively, I could have installed just the Command Line Tools for OS X Mountain Lion found on Apple's Developer site.
    – Drew
    Aug 23, 2013 at 13:21
  • 4
    For my case I had to convert the file authors.txt to utf-8 without BOM.
    – Silvan
    Nov 25, 2015 at 10:31
  • 1
    This worked great for me! Once I had the local repository, I used cmcginty's post starting at "Clone your GIT-SVN repository into a clean Git repository:" I think the main reason I liked @zoul 's answer was is use of git svn init, git svn config then finally git svn fetch as it was easier to do it this way, I had to fetch several times to get it right. cmcginty's single-line git svn clone, which does all three, was too muddled for me.
    – mike
    Jan 9, 2017 at 19:36
74

I used the svn2git script and works like a charm.

6
62

I suggest getting comfortable with Git before trying to use git-svn constantly, i.e. keeping SVN as the centralized repo and using Git locally.

However, for a simple migration with all the history, here are the few simple steps:

Initialize the local repo:

mkdir project
cd project
git svn init http://svn.url

Mark how far back you want to start importing revisions:

git svn fetch -r42

(or just "git svn fetch" for all revs)

Actually, fetch everything since then:

git svn rebase

You can check the result of the import with Gitk. I'm not sure if this works on Windows, it works on OSX and Linux:

gitk

When you've got your SVN repo cloned locally, you may want to push it to a centralized Git repo for easier collaboration.

First create your empty remote repo (maybe on GitHub?):

git remote add origin [email protected]:user/project-name.git

Then, optionally sync your main branch so the pull operation will automatically merge the remote master with your local master when both contain new stuff:

git config branch.master.remote origin
git config branch.master.merge refs/heads/master

After that, you may be interested in trying out my very own git_remote_branch tool, which helps to deal with remote branches:

First explanatory post: "Git remote branches"

Follow-up for the most recent version: "Time to git collaborating with git_remote_branch"

1
  • Extremely helpful, this worked perfectly. I would add that there is one final step to take if you are synching to a remote repository. After the git config steps, I needed to git push origin master
    – mag382
    Oct 24, 2012 at 15:17
33

There is a new solution for smooth migration from Subversion to Git (or for using both simultaneously): SubGit.

I'm working on this project myself. We use SubGit in our repositories - some of my teammates use Git and some Subversion and so far it works very well.

To migrate from Subversion to Git with SubGit you need to run:

$ subgit install svn_repos
...
TRANSLATION SUCCESSFUL 

After that you'll get Git repository in svn_repos/.git and may clone it, or just continue to use Subversion and this new Git repository together: SubGit will make sure that both are always kept in sync.

In case your Subversion repository contains multiple projects, then multiple Git repositories will be created in svn_repos/git directory. To customize translation before running it do the following:

$ subgit configure svn_repos
$ edit svn_repos/conf/subgit.conf (change mapping, add authors mapping, etc)
$ subgit install svn_repos

With SubGit you may migrate to pure Git (not git-svn) and start using it while still keeping Subversion as long as you need it (for your already configured build tools, for instance).

Hope this helps!

3
  • 4
    Note that a one-time import (using the subgit import command) doesn't even seem to require a license. Accurate translation of the svn:ignore property to .gitignore files is included, too.
    – krlmlr
    Mar 4, 2015 at 22:26
  • 2
    SubGit would not recognize my private key, nor any flags that I set in the command line. Documentation is very poor. This is not a viable alternative for git svn.
    – pfnuesel
    Jun 16, 2015 at 11:43
  • 1
    error: 'svn_repos' is not a valid configured location; SubGit configuration file is missing.
    – Jon Davis
    Nov 6, 2015 at 19:37
20

See the official git-svn manpage. In particular, look under "Basic Examples":

Tracking and contributing to an entire Subversion-managed project (complete with a trunk, tags and branches):

# Clone a repo (like git clone):
    git svn clone http://svn.foo.org/project -T trunk -b branches -t tags
1
  • Your clone command worked, those above gave me nothing but empty git repos. The only difference seems to be the explicit '-T trunk'. Nov 26, 2019 at 1:02
15

SubGit (vs Blue Screen of Death)

subgit import --svn-url url://svn.serv/Bla/Bla  directory/path/Local.git.Repo

It's all.

+ To update from SVN, a Git repository is created by the first command.

subgit import  directory/path/Local.git.Repo

I used a way to migrate to Git instantly for a huge repository.
Of course, you need some preparation.
But you may don't stop the development process, at all.

Here is my way.

My solution looks like:

  • Migrate SVN to a Git repository
  • Update the Git repository just before team's switching to.

Migration takes a lot of time for a big SVN repository.
But updating of the completed migration just seconds.

Of course, I'm using SubGit, mama. git-svn makes me Blue Screen of Death. Just constantly. And git-svn is boring me with Git's "filename too long" fatal error.

STEPS

1. Download SubGit

2. Prepare migrate and update commands.

Let's say we do it for Windows (it's trivial to port to Linux).
In a SubGit's installation bin directory (subgit-2.X.X\bin), create two .bat files.

Content of a file/command for the migration:

start    subgit import --svn-url url://svn.serv/Bla/Bla  directory/path/Local.git.Repo

The "start" command is optional here (Windows). It'll allow to see errors on start and left a shell opened after completion of the SubGit.

You may add here additional parameters similar to git-svn. I'm using only --default-domain myCompanyDomain.com to fix the domain of the email address of SVN authors.
I have the standard SVN repository's structure (trunk/branches/tags) and we didn't have troubles with "authors mapping". So I'm doing nothing anymore.

(If you want to migrate tags like branches or your SVN have multiple branches/tags folders you may consider using the more verbose SubGit approach)

Tip 1: Use --minimal-revision YourSvnRevNumber to see fast how things boil out (some kind of a debugging). Especially useful is to see resolved author names or emails.
Or to limit the migration history depth.

Tip 2: Migration may be interrupted (Ctrl + C) and restored by running of the next updating command/file.
I don't advise doing this for big repositories. I have received "Out of memory Java+Windows exception".

Tip 3: Better to create a copy of your result bare repository.

Content of a file/command for updating:

start    subgit import  directory/path/Local.git.Repo

You may run it any amount of time when you want to obtain the last team's commits to your Git repository.

Warning! Don't touch your bare repository (creation of branches for example).
You'll take the next fatal error:

Unrecoverable error: are out of sync and cannot be synced ... Translating Subversion revisions to Git commits...

3. Run the first command/file. It'll take a loooong time for a big repository. 30 hours for my humble repository.

It's all.
You may update your Git repository from SVN at any time any amount of times by running the second file/command. And before switching your development team to Git.
It'll take just seconds.



There's one more useful task.

Push your local Git repository to a remote Git repository

Is it your case? Let's proceed.

  1. Configure your remotes

Run:

$ git remote add origin url://your/repo.git
  1. Prepare to initial send of your huge local Git repository to a remote repository

By default your Git can't send big chunks. fatal: The remote end hung up unexpectedly

Let's run for it:

git config --global http.postBuffer 1073741824

524288000 - 500 MB 1073741824 - 1 GB, etc.

Fix your local certificate troubles. If your git-server uses a broken certificate.

I have disabled certificates.

Also your Git server may have a request amount limitations needing to be corrected.

  1. Push all migration to the team's remote Git repository.

Run with a local Git:

git push origin --mirror

(git push origin '*:*' for old Git versions)

If you get the following: error: cannot spawn git: No such file or directory... For me the full recreation of my repository solves this error (30 hours). You can try the next commands

git push origin --all
git push origin --tags

Or try to reinstall Git (useless for me). Or you may create branches from all you tags and push them. Or, or, or...

14

Pro Git 8.2 explains it: http://git-scm.com/book/en/Git-and-Other-Systems-Migrating-to-Git

1
  • 1
    The Pro Git explanation includes migrating the tags and branches. It uses a local mv rather than svn commands. clever.
    – spazm
    Jun 4, 2011 at 19:19
13

reposurgeon

For complicated cases, reposurgeon by Eric S. Raymond is the tool of choice. In addition to SVN, it supports many other version control systems via the fast-export format, and also CVS. The author reports successful conversions of ancient repositories such as Emacs and FreeBSD.

The tool apparently aims at near perfect conversion (such as converting SVN's svn:ignore properties to .gitignore files) even for difficult repository layouts with a long history. For many cases, other tools might be easier to use.

Before delving into the documentation of the reposurgeon command line, be sure to read the excellent DVCS migration guide which goes over the conversion process step by step.

8

This guide on atlassian's website is one of the best I have found:

https://www.atlassian.com/git/migration

This tool - https://bitbucket.org/atlassian/svn-migration-scripts - is also really useful for generating your authors.txt among other things.

1
  • This page is wonderful, and is IMHO the best answer! It does most of the grunt work for you.
    – PfunnyGuy
    Aug 6, 2018 at 16:38
8

You have to Install

git
git-svn

Copied from this link http://john.albin.net/git/convert-subversion-to-git.

1. Retrieve a list of all Subversion committers

Subversion simply lists the username for each commit. Git’s commits have much richer data, but at its simplest, the commit author needs to have a name and email listed. By default the git-svn tool will just list the SVN username in both the author and email fields. But with a little bit of work, you can create a list of all SVN users and what their corresponding Git name and emails are. This list can be used by git-svn to transform plain svn usernames into proper Git committers.

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 > authors-transform.txt

That will grab all the log messages, pluck out the usernames, eliminate any duplicate usernames, sort the usernames and place them into a “authors-transform.txt” file. Now edit each line in the file. For example, convert:

jwilkins = jwilkins <jwilkins>

into this:

jwilkins = John Albin Wilkins <[email protected]>

2. Clone the Subversion repository using git-svn

git svn clone [SVN repo URL] --no-metadata -A authors-transform.txt --stdlayout ~/temp

This will do the standard git-svn transformation (using the authors-transform.txt file you created in step 1) and place the git repository in the “~/temp” folder inside your home directory.

3. Convert svn:ignore properties to .gitignore

If your svn repo was using svn:ignore properties, you can easily convert this to a .gitignore file using:

cd ~/temp
git svn show-ignore > .gitignore
git add .gitignore
git commit -m 'Convert svn:ignore properties to .gitignore.'

4. Push repository to a bare git repository

First, create a bare repository and make its default branch match svn’s “trunk” branch name.

git init --bare ~/new-bare.git
cd ~/new-bare.git
git symbolic-ref HEAD refs/heads/trunk

Then push the temp repository to the new bare repository.

cd ~/temp
git remote add bare ~/new-bare.git
git config remote.bare.push 'refs/remotes/*:refs/heads/*'
git push bare

You can now safely delete the ~/temp repository.

5. Rename “trunk” branch to “master”

Your main development branch will be named “trunk” which matches the name it was in Subversion. You’ll want to rename it to Git’s standard “master” branch using:

cd ~/new-bare.git
git branch -m trunk master

6. Clean up branches and tags

git-svn makes all of Subversions tags into very-short branches in Git of the form “tags/name”. You’ll want to convert all those branches into actual Git tags using:

cd ~/new-bare.git
git for-each-ref --format='%(refname)' refs/heads/tags |
cut -d / -f 4 |
while read ref
do
  git tag "$ref" "refs/heads/tags/$ref";
  git branch -D "tags/$ref";
done

This step will take a bit of typing. :-) But, don’t worry; your unix shell will provide a > secondary prompt for the extra-long command that starts with git for-each-ref.

7

GitHub now has a feature to import from an SVN repository. I never tried it, though.

2
  • 4
    GitHub's current recommendation is to use the svn2git program suggested in another answer.
    – ntc2
    Jan 30, 2014 at 2:42
  • Imported two quite big projects just now flawlessly. All SVN branches got imported (just remember NOT using \trunk part in repo path). One thing I don't know yet is that whether Github would track new commits.
    – Fr0sT
    Aug 11, 2014 at 12:15
7

A somewhat extended answer using just git, SVN, and bash. It includes steps for SVN repositories that do not use the conventional layout with a trunk/branches/tags directory layout (SVN does absolutely nothing to enforce this kind of layout).

First use this bash script to scan your SVN repo for the different people who contributed and to generate a template for a mapping file:

#!/usr/bin/env bash
authors=$(svn log -q | grep -e '^r' | awk 'BEGIN { FS = "|" } ; { print $2 }' | sort | uniq)
for author in ${authors}; do
  echo "${author} = NAME <USER@DOMAIN>";
done

Use this to create an authors file where you map svn usernames to usernames and email as set by your developers using git config properties user.name and user.email (note that for a service like GitHub only having a matching email is enough).

Then have git svn clone the svn repository to a git repository, telling it about the mapping:

git svn clone --authors-file=authors --stdlayout svn://example.org/Folder/projectroot

This can take incredibly long, since git svn will individually check out every revision for every tag or branch that exists. (note that tags in SVN are just really branches, so they end up as such in Git). You can speed this up by removing old tags and branches in SVN you don't need.

Running this on a server in the same network or on the same server can also really speed this up. Also, if for some reason this process gets interrupted you can resume it using

git svn rebase --continue

In a lot of cases you're done here. But if your SVN repo has an unconventional layout where you simply have a directory in SVN you want to put in a git branch you can do some extra steps.

The simplest is to just make a new SVN repo on your server that does follow convention and use svn copy to put your directory in trunk or a branch. This might be the only way if your directory is all the way at the root of the repo, when I last tried this git svn simply refused to do a checkout.

You can also do this using git. For git svn clone simply use the directory you want to to put in a git branch.

After run

git branch --set-upstream master git-svn
git svn rebase

Note that this required Git 1.7 or higher.

1
7

I've posted an step by step guide (here) to convert svn in to git including converting svn tags in to git tags and svn branches in to git branches.

Short version:

1) clone svn from an specific revision number. (the revision number must be the oldest you want to migrate)

git svn clone --username=yourSvnUsername -T trunk_subdir -t tags_subdir -b branches_subdir -r aRevisionNumber svn_url gitreponame

2) fetch svn data. This step it's the one it takes most time.

cd gitreponame
git svn fetch

repeat git svn fetch until finishes without error

3) get master branch updated

git svn rebase

4) Create local branches from svn branches by copying references

cp .git/refs/remotes/origin/* .git/refs/heads/

5) convert svn tags into git tags

git for-each-ref refs/remotes/origin/tags | sed 's#^.*\([[:xdigit:]]\{40\}\).*refs/remotes/origin/tags/\(.*\)$#\2 \1#g' | while read p; do git tag -m "tag from svn" $p; done

6) Put a repository at a better place like github

git remotes add newrepo [email protected]:aUser/aProjectName.git
git push newrepo refs/heads/*
git push --tags newrepo

If you want more details, read my post or ask me.

0
6

We can use git svn clone commands as below.

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

Above command will create authors file from SVN commits.

  • svn log --stop-on-copy <SVN_URL>

Above command will give you first revision number when your SVN project got created.

  • git svn clone -r<SVN_REV_NO>:HEAD --no-minimize-url --stdlayout --no-metadata --authors-file authors.txt <SVN_URL>

Above command will create the Git repository in local.

Problem is that it won't convert branches and tags to push. You will have to do them manually. For example below for branches:

$ git remote add origin https://github.com/pankaj0323/JDProjects.git
$ git branch -a
* master
  remotes/origin/MyDevBranch
  remotes/origin/tags/MyDevBranch-1.0
  remotes/origin/trunk
$$ git checkout -b MyDevBranch origin/MyDevBranch
Branch MyDevBranch set up to track remote branch MyDevBranch from origin.
Switched to a new branch 'MyDevBranch'
$ git branch -a
* MyDevBranch
  master
  remotes/origin/MyDevBranch
  remotes/origin/tags/MyDevBranch-1.0
  remotes/origin/trunk
$

For tags:

$git checkout origin/tags/MyDevBranch-1.0
Note: checking out 'origin/tags/MyDevBranch-1.0'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at 3041d81... Creating a tag
$ git branch -a
* (detached from origin/tags/MyDevBranch-1.0)
  MyDevBranch
  master
  remotes/origin/MyDevBranch
  remotes/origin/tags/MyDevBranch-1.0
  remotes/origin/trunk
$ git tag -a MyDevBranch-1.0 -m "creating tag"
$git tag
MyDevBranch-1.0
$

Now push master, branches and tags to remote git repository.

$ git push origin master MyDevBranch MyDevBranch-1.0
Counting objects: 14, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (14/14), 2.28 KiB | 0 bytes/s, done.
Total 14 (delta 3), reused 0 (delta 0)
To https://github.com/pankaj0323/JDProjects.git
 * [new branch]      master -> master
 * [new branch]      MyDevBranch -> MyDevBranch
 * [new tag]         MyDevBranch-1.0 -> MyDevBranch-1.0
$

svn2git utility

svn2git utility removes manual efforts with branches and tags.

Install it using command sudo gem install svn2git. After that run below command.

  • $ svn2git <SVN_URL> --authors authors.txt --revision <SVN_REV_NO>

Now you can list the branches, tags and push them easily.

$ git remote add origin https://github.com/pankaj0323/JDProjects.git
$ git branch -a
  MyDevBranch
* master
  remotes/svn/MyDevBranch
  remotes/svn/trunk
$ git tag
  MyDevBranch-1.0
$ git push origin master MyDevBranch MyDevBranch-1.0

Imagine you have 20 branches and tags, obviously svn2git will save you a lot of time and that's why I like it better than native commands. It's a nice wrapper around native git svn clone command.

For a complete example, refer my blog entry.

5

TortoiseGit does this. see this blog post: http://jimmykeen.net/articles/03-nov-2012/how-migrate-from-svn-to-git-windows-using-tortoise-clients

Yeah, I know answering with links isn't splendid but it's a solution, eh?

1
  • Try the wayback machine at archive.org
    – CAD bloke
    May 10, 2019 at 20:08
5

For GitLab users I've put up a gist on how I migrated from SVN here:

https://gist.github.com/leftclickben/322b7a3042cbe97ed2af

Steps to migrate from SVN to GitLab

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 [email protected]).
    • 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 <[email protected]>, 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 [email protected]: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.
2
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.
    – Blackhole
    May 4, 2015 at 21:09
  • 1
    I disagree. The linked content might change, and the content duplicated here will not be updated, and therefore might be out of date (and in fact I believe it has changed since I originally posted this answer). The guidelines only say to include some relevant context for a link, which I did -- the actual question was answered wholesale by the link. Copying the whole linked resource here is not required or necessary. Was I downvoted for this?! May 6, 2015 at 6:38
3

I highly recommend this short series of screencasts I just discovered. The author walks you through the basic operations, and showcases some more advanced usages.

3

If you are using SourceTree you can do this directly from the app. Goto File -> New/Clone then do the following:

  1. Enter the remote SVN URL as the "Source Path / URL".
  2. Enter your credentials when prompted.
  3. Enter the local folder location as the "Destination path".
  4. Give it a name.
  5. In the advanced options select "Git" from the dropdown in "Create local repository of type".
  6. You can optionally specify a revision to clone from.
  7. Hit Clone.

Open the repo in SourceTree and you'll see your commit messages have been migrated too.

Now go to Repository -> Repository Settings and add the new remote repo details. Delete the SVN remote if you wish (I did this through the "Edit Config File" option.

Push the code to the new remote repo when you are ready and code freely.

1
  • Thank you.This worked for me.I am using SourceTree and Stash.
    – nobody
    Oct 20, 2015 at 16:21
2

As another aside, the git-stash command is a godsend when trying to git with git-svn dcommits.

A typical process:

  1. set up git repo
  2. do some work on different files
  3. decide to check some of the work in, using git
  4. decide to svn-dcommit
  5. get the dreaded "cannot commit with a dirty index" error.

The solution (requires git 1.5.3+):

git stash; git svn dcommit ; git stash apply
2

I just wanted to add my contribution to the Git community. I wrote a simple bash script which automates the full import. Unlike other migration tools, this tool relies on native git instead of jGit. This tool also supports repositories with a large revision history and or large blobs. It's available via github:

https://github.com/onepremise/SGMS

This script will convert projects stored in SVN with the following format:

/trunk
  /Project1
  /Project2
/branches
     /Project1
     /Project2
/tags
 /Project1
 /Project2

This scheme is also popular and supported as well:

/Project1
     /trunk
     /branches
     /tags
/Project2
     /trunk
     /branches
     /tags

Each project will get synchronized over by project name:

Ex: ./migration https://svnurl.com/basepath project1

If you wish to convert the full repo over, use the following syntax:

Ex: ./migration https://svnurl.com/basepath .
2

Here is a simple shell script with no dependencies that will convert one or more SVN repositories to git and push them to GitHub.

https://gist.github.com/NathanSweet/7327535

In about 30 lines of script it: clones using git SVN, creates a .gitignore file from SVN::ignore properties, pushes into a bare git repository, renames SVN trunk to master, converts SVN tags to git tags, and pushes it to GitHub while preserving the tags.

I went thru a lot of pain to move a dozen SVN repositories from Google Code to GitHub. It didn't help that I used Windows. Ruby was all kinds of broken on my old Debian box and getting it working on Windows was a joke. Other solutions failed to work with Cygwin paths. Even once I got something working, I couldn't figure out how to get the tags to show up on GitHub (the secret is --follow-tags).

In the end I cobbled together two short and simple scripts, linked above, and it works great. The solution does not need to be any more complicated than that!

1
  • 2
    I used this script. After a bit of trail and error, it worked for me. Please be advised that you need Git 1.8.3+ for this, as --follow-tags is only supported thereafter.
    – nrobey
    Feb 17, 2014 at 19:41
2

I´m on a windows machine and made a small Batch to transfer a SVN repo with history (but without branches) to a GIT repo by just calling

transfer.bat http://svn.my.address/svn/myrepo/trunk https://git.my.address/orga/myrepo

Perhaps anybody can use it. It creates a TMP-folder checks out the SVN repo there with git and adds the new origin and pushes it... and deletes the folder again.

@echo off 
SET FROM=%1 
SET TO=%2 
SET TMP=tmp_%random%

echo from:  %FROM% 
echo to:    %TO% 
echo tmp:   %TMP%

pause

git svn clone  --no-metadata --authors-file=users.txt %FROM% %TMP%  
cd %TMP% 
git remote add origin %TO% 
git push --set-upstream origin master


cd .. 
echo delete %TMP% ... 
pause

rmdir /s /q %TMP%

You still need the users.txt with your user-mappings like

User1 = User One <[email protected]>
4
  • This answer helped me to move all my repositories to BitBucket without problems. May 28, 2018 at 12:28
  • Glad to hear. I had only experience with Gitea... but tranferred ~~40 repos this way.
    – cljk
    May 29, 2018 at 13:24
  • Very nice! Thnx
    – aLx13
    Apr 1, 2019 at 14:21
  • warning; I experienced bad charset issues. I recognized this really too late but it took me several hours fixing. Please check that your resulting repo contains the exact(!) expected sources
    – cljk
    Apr 2, 2019 at 15:29
1

Converting svn submodule/folder 'MyModule' into git with history without tags nor branches.

To retain svn ignore list use the above comments after step 1

1

First, credit to the answer from @cmcginty. It was a great starting point for me, and much of what I'll post here borrowed heavily from it. However, the repos that I was moving have years of history which led to a few issues following that answer to the letter (hundreds of branches and tags that would need to be manually moved for one; read more later).

So after hours of searching and trial and error I was able to put together a script which allowed me to easily move several projects from SVN to GIT, and I've decided to share my findings here in case anyone else is in my shoes.

<tl;dr> Let's get started


First, create an 'Authors' file which will translate basic svn users to more complex git users. The easiest way to do this is using a command to extract all users from the svn repo you are going to move.

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

This will produce a file called authors-transform.txt with a line for each user that has made a change in the svn repo it was ran from.

someuser = someuser <someuser>

Update to include full name and email for git

someuser = Some User <[email protected]>

Now start the clone using your authors file

git svn clone --stdlayout --no-metadata -r854:HEAD --authors-file=authors-transform.txt https://somesvnserver/somerepo/ temp
  • --stdlayout indicates that the svn repo follows the standard /trunk /branches /tags layout
  • --no-metadata tells git not to stamp metadata relating to the svn commits on each git commit. If this is not a one-way conversion remove this tag
  • -r854:HEAD only fetches history from revision 854 up. This is where I hit my first snag; the repo I was converting had a 'corrupted' commit at revision 853 so it would not clone. Using this parameter allows you to only clone part of the history.
  • temp is the name of the directory that will be created to initialize the new git repo

This step can take awhile, particularly on a large or old repo (roughly 18 hours for one of ours). You can also use that -r switch to only take a small history to see the clone, and fetch the rest later.

Move to the new directory

cd temp

Fetch any missing history if you only pulled partial in clone

git svn fetch

Tags are created as branches during cloning. If you only have a few you can convert them one at a time.

git 1.0.0 origin/tags/1.0.0

However, this is tedious if you have hundreds of tags, so the following script worked for me.

for brname in `git branch -r | grep tags | awk '{gsub(/^[^\/]+\//,"",$1); print $1}'`; do echo $brname; tname=${brname:5}; echo $tname; git tag $tname origin/tags/$tname; done

You also need to checkout all branches you want to keep

git checkout -b branchname origin/branches/branchname

And if you have a lot of branches as well, this script may help

for brname in `git branch -r | grep -v master | grep -v HEAD | grep -v trunk | grep -v tags | awk '{gsub(/^[^\/]+\//,"",$1); print $1}'`; do echo $brname; git checkout -b $brname origin/$brname; done

This will ignore the trunk branch, as it will already be checked out as master and save a step later deleting the duplicate branch, as well as ignoring the /tags that we already converted.

Now is a good time to take a look at the new repo and make sure you have a local branch or tag for anything you want to keep as remote branches will be dropped in a moment.

Ok, now lets clone everything we've checked out to a clean repo (named temp2 here)

cd ..
git clone temp temp2
cd temp2

Now we'll need to checkout all of the branches one more time before pushing them to their final remote, so follow your favorite method from above.

If you're following gitflow you can rename your working branch to develop.

git checkout -b WORKING
git branch -m develop
git push origin --delete WORKING
git push origin -u develop

Now, if everything looks good, you're ready to push to your git repository

git remote set-url origin https://somebitbucketserver/somerepo.git
git push -u origin --all
git push origin --tags

I did run into one final issue which was that Control Freak initially blocked me from pushing tags that I didn't create, so if your team uses Control Freak you may need to disable or adjust that setting for your initial push.

0

Effectively using Git with Subversion is a gentle introduction to git-svn. For existing SVN repositories, git-svn makes this super easy. If you're starting a new repository, it's vastly easier to first create an empty SVN repository and then import using git-svn than it is going in the opposite direction. Creating a new Git repository then importing into SVN can be done, but it is a bit painful, especially if you're new to Git and hope to preserve the commit history.

0

Download the Ruby installer for Windows and install the latest version with it. Add Ruby executables to your path.

  • Install svn2git
  • Start menu -> All programs -> Ruby -> Start a command prompt with Ruby
  • Then type “gem install svn2git” and enter

    Migrate Subversion repository

  • Open a Ruby command prompt and go to the directory where the files are to be migrated

    Then svn2git http://[domain name]/svn/ [repository root]

  • It may take few hours to migrate the project to Git depends on the project code size.

  • This major step helps in creating the Git repository structure as mentioned below.

    SVN (/Project_components) trunk --> Git master SVN (/Project_components) branches --> Git branches SVN (/Project_components) tags --> Git tags

Create the remote repository and push the changes.

0

GitHub has an importer. Once you've created the repository, you can import from an existing repository, via its URL. It will ask for your credentials if applicable and go from there.

As it's running it will find authors, and you can simply map them to users on GitHub.

I have used it for a few repositories now, and it's pretty accurate and much faster too! It took 10 minutes for a repository with ~4000 commits, and after it took my friend four days!

0

Several answers here refer to https://github.com/nirvdrum/svn2git, but for large repositories this can be slow. I had a try using https://github.com/svn-all-fast-export/svn2git instead which is a tool with exactly the same name but was used to migrate KDE from SVN to Git.

Slightly more work to set it up but when done the conversion itself for me took minutes where the other script spent hours.

Not the answer you're looking for? Browse other questions tagged or ask your own question.