1549

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Milan Babuškov
  • 55,232
  • 47
  • 119
  • 176
  • 7
    It is getting easier, I just completed it myself and documented my findings with the help of SO http://jmoses.co/2014/03/21/moving-from-svn-to-git.html – John Moses Mar 21 '14 at 21:20
  • Use Casey's answer below, but before you run the "svn clone ..." command, see how to add the extra "Visual SVN Server" line to your user.txt file... here: http://stackoverflow.com/questions/8971208/svn2git-failing-saying-author-visualsvn-server-not-defined-in-authors-txt-fil – MacGyver Feb 09 '16 at 07:21
  • 1
    Also, if you have the "make email private option checked in your GitHub profile, use this as your email address in users.txt to match. yourgituser@users.noreply.github.com, so your real email address doesn't show up on commits. – MacGyver Feb 09 '16 at 07:39
  • Related: [Migrating from SVN to Git, preserving branches and tags](http://www.sailmaker.co.uk/blog/2013/05/05/migrating-from-svn-to-git-preserving-branches-and-tags-3/) – kenorb Jun 20 '20 at 19:20
  • To migrate from Google Code, read: [How to recover a Google Code SVN Project and migrate to Github](https://dominikdorn.com/2016/05/how-to-recover-a-google-code-svn-project-and-migrate-to-github/) – kenorb Jun 20 '20 at 19:22

33 Answers33

1593

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

user1 = First Last Name <email@address.com>
user2 = First Last Name <email@address.com>
...

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/freezed", 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 indicates 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 setup 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 name

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 new 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
cmcginty
  • 101,562
  • 37
  • 148
  • 155
  • 1
    Thank you very much for this! I did all the basic import steps and then noticed that all my branches were remotes and wasn't sure what to do to resolve it. – latortuga Dec 02 '10 at 15:01
  • 37
    This blog post by Eelke is a great cross-reference for the answer above. http://blokspeed.net/blog/2010/09/converting-from-subversion-to-git/ – kgriffs Mar 06 '12 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) – Dirty Henry Mar 29 '12 at 09:22
  • I too have been struggeling with the branches part. After migrating a SVN repo with five branches and following this guide only one branch were checked out. I think there is missing a "git pull" command somewhere??? Also: If i do the step that removes the remote branches, my local branches are also removed. - So i don't see the point in removing the remote branches. So I skipped the last step where you cut out the remote and now (I think) it works as supposed to. – esbenr Apr 01 '12 at 10:51
  • You could add this step to find all users who committed to the repo. http://superuser.com/questions/130326/list-of-all-users-who-committed-to-a-svn-repository – Johnny Everson Apr 11 '12 at 00:25
  • I find that `git svn clone` bombs when using the ``--no-metadata`` flag http://stackoverflow.com/questions/11398415/git-svn-clone-fails-unexpectedly – nw. Jul 09 '12 at 16:42
  • Try to look also to http://john.albin.net/git/convert-subversion-to-git It seems a very good step-by-step procedure – daitangio Aug 07 '12 at 14:49
  • 3
    I just used this procedure and it worked pretty well. My observations are: 1) the process for converting "tag branches" to tags still leaves the branches (albeit unlabelled). If you created the tag in SVN without modifying the content, then you can actually tag the preceding commit and delete the "tag-branch" for cleaner history. 2) no mention is made of migrating the svn:ignore attributes. This is covered elsewhere on The Internet. See also 'git svn show-ignore'. 3) the final clone didn't benefit me. Indeed, I ended up with remote refs to the original dir, which was odd. – dty Sep 21 '12 at 14:30
  • 4
    GitHub has a very convenient step-by-step: https://github.com/nirvdrum/svn2git#readme – Dan Nissenbaum Oct 17 '12 at 14:11
  • 2
    I had to add an '(no author)' line in my users.txt file as mentioned here: http://blokspeed.net/blog/2010/09/converting-from-subversion-to-git/ I also got `Use of uninitialized value in substitution` and had to follow this: https://groups.google.com/forum/?fromgroups=#!topic/msysgit/7MQVwRO-2N4 – GlenPeterson Nov 17 '12 at 21:02
  • 2
    And I had to remove spaces near the `=` character from `users.txt` because `somebody = Somebody ` didn't work (import aborted after first commit, leaving an empty repository) but `somebody=Somebody ` worked fine. – Sebastián Grignoli Jan 31 '13 at 03:06
  • 1
    Ah yes, the [git documentation link](http://git-scm.com/book/en/Git-and-Other-Systems-Migrating-to-Git) provided in [kpd's answer](http://stackoverflow.com/a/4974152/210945) has a nice way to get the SVN users. – naught101 Apr 18 '13 at 05:52
  • 1
    Thanks for the wonderful answer. I needed to extract a project out of a non-stdlayout repo. The project lived in a repo subfolder and had it's own trunk/branches/tags sub-structure. I had to use the base repo path and `--trunk=Path/To/MyProject/trunk` option. I didn't specify any branch or tag option as these were not required. I had some strange behaviour where `git svn` kept stopping early and the final trunk was not the latest svn commit. Finally figured out that I had to `cd dest_dir-temp` and `git svn fetch` multiple times until got the latest revision! – Aranda Apr 22 '13 at 02:39
  • 1
    If the svn repository changes since you did the initial `git svn clone` (or after `git svn fetch` if there were interrupts), the `master` branch diverts from the remote `trunk` when svn fetching again. To fix this before you clone your temp repo in the clean repo use `git checkout master` and `git reset --hard trunk`. Now `master` points to latest revision from trunk again. – v01pe May 14 '13 at 14:47
  • I would checkout svn repo first and do this to populate users.txt `svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" "}' | sort -u > users.txt` – holms Jul 16 '13 at 09:53
  • 2
    Should probably update this with: `git svn show-ignore > .gitignore` – getWeberForStackExchange Oct 02 '13 at 23:52
  • 8
    For those under Windows, I created a PowerShell script based on this method: https://gist.github.com/Gimly/90df046dc38181bb18de – Gimly Jun 16 '14 at 09:42
  • For create tag in one command `git checkout -b tagg origin/tags/1.0 ; git checkout master;git tag v1.0 tagg;git branch -D tagg;` Only change tagname 1.0. – cubaguest Mar 13 '15 at 16:15
  • 6
    **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 04 '15 at 13:01
  • 1
    @Jess: Just as a note, but the reason it's so slow is that Git has to turn each Subversion check-in into a local commit as it builds up the repo. A large repo can take several hours (even overnight), so I'd recommend planning ahead – code_dredd Oct 01 '15 at 01:17
  • I had some commit messages which included the word "author". using `grep "" ` instead of just `grep "author" ` avoided adding extra lines to the template file. Also, since our usernames are of the form firstname.lastname I can actually use ` svn log --xml | grep "" | sort -u | perl -pe 's/.*>(.*?)<. sed="">/'` to generate the whole file! haven't got as far as the actual import yet since our SVN structure is not totally standard but looks good. – Adam Oct 02 '15 at 14:55
  • Or, even shorter `svn log --xml | sed -n 's/^\(.*\)\.\(.*\)/\1.\2 = \u\1 \u\2 /p' | sort -u` Surprisingly this runs if anything very slightly faster than even the original version with grep and perl. – Adam Oct 02 '15 at 15:10
  • you'll need to create a bare git repository and to import the cloned git files there, if you're hosting your git repository by your own –  Dec 02 '15 at 10:47
  • May I use the standard layout even though I don't have branch and tag subfolders, but only trunk? –  May 04 '16 at 10:41
  • To retrieve the SVN repository, @zoul 's post below was easier to follow because of git svn init and git svn fetch commands instead of git svn clone. Once I had the repository, this post was very helpful to get it cleaned up with git clone. – mike Jan 09 '17 at 19:31
  • I don't know how many times it's been copied, but to preserve vestiges I have to note this answer looks almost a verbatim copy of: https://git.help.collab.net/hc/en-us/community/posts/238452907-Migration-from-Subversion-to-GIT – Josh Habdas Jun 24 '17 at 03:33
  • What would you do with the old svn repo once you move to git? Shut it down completely? Is there any reason to keep it available? – Liam Jul 27 '17 at 19:56
  • Tip: if `--authors-file` doesn't work in your case (for example because a svn username ends with a space) then use the `--authors-prog` option instead which allows supplying a script doing the mapping from svn user to git user. – josch Feb 07 '18 at 07:40
  • @SebastiánGrignoli I was unable to confirm your observation with git-svn 2.15. In fact, my `users.txt` had even more than one space in front and behind the equal sign to align them all by the same text column and it worked. – josch Feb 07 '18 at 07:44
  • I too got the `Use of uninitialized value in substitution` error. I'm on Linux but I found [this link](https://stackoverflow.com/a/4434188/2903608) on SO useful. I.e. delete everything under the [svn-remote "svn"] section. – PhilPhil Feb 09 '18 at 15:26
  • If that helps.. I created the following powershell script to grab the authors: – xav Dec 19 '20 at 00:38
532

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
Hammad
  • 41
  • 8
jfm3
  • 34,220
  • 10
  • 29
  • 35
  • Use CPAN to install the Error module, I think. You can use git-svn for a one-time migration. – emk Sep 17 '08 at 13:07
  • @Milan: I get this error when the subversion perl bindings are not installed. – EfForEffort Sep 17 '08 at 17:06
  • 143
    The answer from @Casey answers the original question much better. – Doug Wilson Feb 26 '12 at 14:58
  • 3
    Will this keep the branches and everything? or just clone the trunk? – Heetola Sep 25 '12 at 19:16
  • 7
    @Eildosa: This will just clone the trunk. See Casey's answer for an alternative. – sleske Aug 10 '13 at 13:30
  • It does not preserve commit date times. Is there any workaround? I have found some releated topic http://stackoverflow.com/questions/6795070/is-there-a-way-in-git-to-obtain-a-push-date-for-a-given-commit. I don't know if it is possible to use it from git svn clone. – Tomas Kubes May 05 '14 at 15:01
  • 3
    @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"? – Andrey Regentov Aug 05 '16 at 08:50
  • 74
    For anyone else who's wondering which is "Casey's answer" which is referenced in lots of comments around here, it's [this one](http://stackoverflow.com/a/3972103/122687) (Casey changed his nick to cmcginty). – Stefan Monov Oct 05 '16 at 10:35
  • This basically works but there is more to it. For example migrating / matching user names or working on both repos at the same time during transition period. Here are some more details I found: https://itcodehub.blogspot.com/2015/08/how-to-migrate-svn-repository-to-git.html – xproph Mar 26 '19 at 21:55
198

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 <jon@gmail.com>
bigpappa = Brian Biggs <bigpappa@gmail.com>

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
Daniel Gray
  • 1,369
  • 1
  • 17
  • 37
Eugene Yokota
  • 90,473
  • 43
  • 204
  • 301
  • 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. – Sebastián Grignoli Jan 31 '13 at 03: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. – Daniel Reis Jun 05 '13 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 '13 at 13:21
  • 3
    For my case I had to convert the file `authors.txt` to `utf-8 without BOM`. – Silvan Nov 25 '15 at 10:31
  • 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 09 '17 at 19:36
  • This is the only thing that worked great for me. However, it does not only migrate the repository, but it also creates the workspace (extracts the repository files to the disk). Any way to avoid this and only keep the `.git` folder? – NoOne Mar 10 '18 at 21:13
72

I used the svn2git script and works like a charm.

Uwe Keim
  • 36,867
  • 50
  • 163
  • 268
  • 4
    Q: does this fix spaces in tag and branch names (allowed in svn and not allowed in git)? – spazm Jun 04 '11 at 19:16
  • 2
    This guide to use it is helpful: http://www.troyhunt.com/2014/08/migrating-from-subversion-to-git-with.html – Morten Holmgaard Feb 08 '15 at 19:25
  • This failed for me with a problem: https://groups.google.com/forum/#!topic/msysgit/7MQVwRO-2N4 - see also: https://github.com/nirvdrum/svn2git/issues/50 The solution was here: http://stackoverflow.com/questions/3009738/what-does-this-svn2git-error-mean/4434188#4434188 – HDave Dec 08 '16 at 16:03
  • It's preferable to explain answers otherwise we produce script kiddies. – Josh Habdas Jun 24 '17 at 04:19
  • What about if your branches are all in the root of SVN and you have no trunk or tags? – Kal Dec 06 '17 at 12:34
  • It seems the repo is unactive now. It has 145 open issues and 30 open pr on the repository. – wonsuc Dec 10 '20 at 01:23
59

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 git@github.com: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 dealing with remote branches:

First explanatory post: "Git remote branches"

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

the Tin Man
  • 150,910
  • 39
  • 198
  • 279
webmat
  • 50,648
  • 12
  • 52
  • 59
  • 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 '12 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!

Uwe Keim
  • 36,867
  • 50
  • 163
  • 268
  • 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 04 '15 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 '15 at 11:43
  • 1
    error: 'svn_repos' is not a valid configured location; SubGit configuration file is missing. – Jon Davis Nov 06 '15 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
EfForEffort
  • 55,496
  • 4
  • 33
  • 39
  • Your clone command worked, those above gave me nothing but empty git repos. The only difference seems to be the explicit '-T trunk'. – user1984717 Nov 26 '19 at 01:02
14

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 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 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 updating 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 any more.

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

Tip 1: Use --minimal-revision YourSvnRevNumber to see fast how things boils 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 times 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 of 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...

Community
  • 1
  • 1
it3xl
  • 1,279
  • 14
  • 28
14

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

Ryan Edwards
  • 623
  • 1
  • 10
  • 26
kdahlhaus
  • 462
  • 5
  • 8
  • 1
    The Pro Git explanation includes migrating the tags and branches. It uses a local mv rather than svn commands. clever. – spazm Jun 04 '11 at 19:19
12

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
krlmlr
  • 22,030
  • 13
  • 107
  • 191
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.

Andrew B
  • 1,538
  • 2
  • 20
  • 30
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 <johnalbin@example.com>

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.

Valarpirai
  • 1
  • 1
  • 1
7

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

webmat
  • 50,648
  • 12
  • 52
  • 59
  • 3
    GitHub's [current recommendation](https://help.github.com/articles/importing-from-subversion) is to use the `svn2git` program suggested in [another answer](http://stackoverflow.com/a/4860157/470844). – ntc2 Jan 30 '14 at 02: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 '14 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.

thoutbeckers
  • 2,392
  • 20
  • 22
  • I would propose to combine this info with this link: http://www.sailmaker.co.uk/blog/2013/05/05/migrating-from-svn-to-git-preserving-branches-and-tags-3/ – Joan P.S Nov 11 '13 at 10:09
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 git@github.com:aUser/aProjectName.git
git push newrepo refs/heads/*
git push --tags newrepo

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

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.

Pankaj
  • 4,738
  • 3
  • 25
  • 36
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?

CAD bloke
  • 7,546
  • 6
  • 58
  • 104
4

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 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

bash
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.
Community
  • 1
  • 1
leftclickben
  • 4,344
  • 19
  • 24
  • 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 04 '15 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?! – leftclickben May 06 '15 at 06:38
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.

Craig Myles
  • 3,739
  • 3
  • 31
  • 34
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.

ripper234
  • 202,011
  • 255
  • 600
  • 878
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
Gregg Lind
  • 18,936
  • 15
  • 63
  • 80
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!

NateS
  • 5,747
  • 4
  • 46
  • 53
  • 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+](https://github.com/git/git/blob/master/Documentation/RelNotes/1.8.3.txt#L155-L156) for this, as --follow-tags is only supported thereafter. – nrobey Feb 17 '14 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 <u.1@xxx.com>
cljk
  • 856
  • 1
  • 7
  • 17
  • This answer helped me to move all my repositories to BitBucket without problems. – Gonzalingui May 28 '18 at 12:28
  • Glad to hear. I had only experience with Gitea... but tranferred ~~40 repos this way. – cljk May 29 '18 at 13:24
  • Very nice! Thnx – b3wii Apr 01 '19 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 02 '19 at 15:29
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 .
Jason Huntley
  • 3,719
  • 2
  • 17
  • 26
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 <someuser@somewhere.com>

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.

dgates82
  • 53
  • 1
  • 7
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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Nanda
  • 105
  • 1
  • 10
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!

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
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.

Zitrax
  • 16,107
  • 15
  • 79
  • 98
0

There are different methods to achieve this goal. I've tried some of them and found really working one with just git and svn installed on Windows OS.

Prerequisites:

  1. git on windows (I've used this one) https://git-scm.com/
  2. svn with console tools installed (I've used tortoise svn)
  3. Dump file of your SVN repository. svnadmin dump /path/to/repository > repo_name.svn_dump

Steps to achieve final goal (move all repository with history to a git, firstly local git, then remote)

  1. Create empty repository (using console tools or tortoiseSVN) in directory REPO_NAME_FOLDER cd REPO_NAME_PARENT_FOLDER, put dumpfile.dump into REPO_NAME_PARENT_FOLDER

  2. svnadmin load REPO_NAME_FOLDER < dumpfile.dump Wait for this operation, it may be long

  3. This command is silent, so open second cmd window : svnserve -d -R --root REPO_NAME_FOLDER Why not just use file:///...... ? Cause next command will fail with Unable to open ... to URL:, thanks to the answer https://stackoverflow.com/a/6300968/4953065

  4. Create new folder SOURCE_GIT_FOLDER

  5. cd SOURCE_GIT_FOLDER
  6. git svn clone svn://localhost/ Wait for this operation.

Finally, what do we got?

Lets check our Local repository :

git log

See your previous commits? If yes - okay

So now you have fully functional local git repository with your sources and old svn history. Now, if you want to move it to some server, use the following commands :

git remote add origin https://fullurlpathtoyourrepo/reponame.git
git push -u origin --all # pushes up the repo and its refs for the first time
git push -u origin --tags # pushes up any tags

In my case, I've dont need tags command cause my repo dont have tags.

Good luck!

Community
  • 1
  • 1
Ruslan Makrenko
  • 1,207
  • 9
  • 9
0

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

PShetty
  • 465
  • 6
  • 10
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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
burkestar
  • 743
  • 1
  • 4
  • 12
0

I used the following script to read a text file that has a list of all my SVN repositories and convert them to Git, and later use git clone --bare to convert to a bare Git repository:

#!/bin/bash
file="list.txt"
while IFS= read -r repo_name
do
 printf '%s\n' "$repo_name"
 sudo git svn clone --shared --preserve-empty-dirs --authors-file=users.txt file:///programs/svn/$repo_name
 sudo git clone --bare /programs/git/$repo_name $repo_name.git
 sudo chown -R www-data:www-data $repo_name.git
 sudo rm -rf $repo_name
done <"$file"

list.txt has the format:

repo1_name
repo2_name

And users.txt has the format:

(no author) = Prince Rogers <prince.rogers.nelson@payesley.park.org>

www-data is the Apache web server user, and permission is needed to push changes over HTTP.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Pedro Vicente
  • 443
  • 1
  • 5
  • 17
-1

For this, I have used svn2git library with the following procedure:

sudo apt-get install git-core git-svn ruby
sudo gem install svn2git
svn log --quiet | grep -E "r[0-9]+ \| .+ \|" | cut -d'|' -f2 | sed 's/ //g' | sort | uniq > authors.txt (this command is for mapping the authors)

Above step should be performed in the folder that you are going to convert from svn to git.

Add one mapping per line in authors.txt like this

anand = Anand Tripathi <email_id>
trip = Tripathi Anand <email_id>

Create a folder for a new git repository and execute the command below having the path of authors.txt

svn2git <svn_repo_path> --nobranches --notags --notrunk --no-minimize-url --username <user_name> --verbose  --authors <author.txt_path>

If no trunk and no tag and branch is present then have to execute the above command else if root is trunk then mention rootistrunk or trunk is present then --trunk <trunk_name>

git remote add origin
git push --all origin
git push --tags origin

Anand Tripathi
  • 8,458
  • 1
  • 30
  • 38