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.
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.You have to Install
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:
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:
into this:
2. Clone the Subversion repository using git-svn
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:
4. Push repository to a bare git repository
First, create a bare repository and make its default branch match svn’s “trunk” branch name.
Then push the temp repository to the new bare repository.
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:
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:
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.
Pro Git 8.2 explains it: http://git-scm.com/book/en/Git-and-Other-Systems-Migrating-to-Git
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:
For tags:
Now push master, branches and tags to remote git repository.
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.
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.
As another aside, the git-stash command is a godsend when trying to git with git-svn dcommits.
A typical process:
svn-dcommit
The solution (requires git 1.5.3+):
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.