How do I migrate an SVN repository with history to a new Git repository?
-
09-06-2019 - |
Question
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.
Solution
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
man page has a good examples section:
$ git svn --help
OTHER TIPS
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/ {sub("^ ", "", $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. That 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
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
I used the svn2git script and works like a charm.
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"
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!
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
Pro Git 8.2 explains it: http://git-scm.com/book/en/Git-and-Other-Systems-Migrating-to-Git
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
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.
- Configure your remotes
Run:
$ git remote add origin url://your/repo.git
- 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.
- 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...
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.
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.
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.
GitHub now has a feature to import from an SVN repository. I never tried it, though.
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.
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.
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.
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?
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.
If you are using SourceTree you can do this directly from the app. Goto File -> New/Clone then do the following:
- Enter the remote SVN URL as the "Source Path / URL".
- Enter your credentials when prompted.
- Enter the local folder location as the "Destination path".
- Give it a name.
- In the advanced options select "Git" from the dropdown in "Create local repository of type".
- You can optionally specify a revision to clone from.
- 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.
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 thedev-team
namespace.
- A group is created with the namespace
- The file
users.txt
contains the relevant user details, one user per line, of the formusername = First Last <address@domain.com.au>
, whereusername
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, updateusers.txt
,cd favourite-project
andgit 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 abovetrunk/
,tags/
andbranches/
. - The
git svn clone
command produces a lot of output, including some warnings at the top; I ignored the warnings.
As another aside, the git-stash command is a godsend when trying to git with git-svn dcommits.
A typical process:
- set up git repo
- do some work on different files
- decide to check some of the work in, using git
- decide to
svn-dcommit
- 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
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!
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>
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 .
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.
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.
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!
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.
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:
- git on windows (I've used this one) https://git-scm.com/
- svn with console tools installed (I've used tortoise svn)
- 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)
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_FOLDERsvnadmin load REPO_NAME_FOLDER < dumpfile.dump
Wait for this operation, it may be longThis 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 withUnable to open ... to URL:
, thanks to the answer https://stackoverflow.com/a/6300968/4953065Create new folder SOURCE_GIT_FOLDER
cd SOURCE_GIT_FOLDER
- 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!
Converting svn submodule/folder 'MyModule' into git with history without tags nor branches.
- git svn clone --no-metadata --trunk=SomeFolder1/SomeFolder2/SomeFolder3/MyModule http://svnhost:port/repo_root_folder/MyModule_temp -A C:\cheetah\svn\authors-transform.txt
- git clone MyModule_temp MyModule
- cd MyModule
- git flow init
- git remote set-url origin https://userid@stashhost/stash/scm/xyzxyz/MyModule.git
- git push -u origin master
- git push -u origin develop
To retain svn ignore list use the above comments after step 1