Converting a Subversion repository to git

Hello,

I'm somewhat new to git and was trying to find the best way to convert my Subversion repositories over to git. I have been looking at the git- svn command, which seems to be the way to do it. However, git-svn seems to be a two-way communication between svn and git. I don't want two-way, I want a pure git repository that maintains the history from a svn repository.

The repositories I'm converting are my own, and once they are moved over to git the svn repository will no longer be maintained and will likely be deleted completely from my system.

So can git-svn be used for this? Are there options to git-svn to just use the tool as a one-way converter? What are other people doing in this case?

I suppose I could simply export my svn repositories without version history and just git init, but I'd rather not lose my change history if there's a convenient way to do that.

Robert Walker wrote:

Hello,

I'm somewhat new to git and was trying to find the best way to convert my Subversion repositories over to git. I have been looking at the git- svn command, which seems to be the way to do it. However, git-svn seems to be a two-way communication between svn and git. I don't want two-way, I want a pure git repository that maintains the history from a svn repository.

It is now the ONLY way, as of GiT 1.5.5 git-svnimport is depreciated.

The repositories I'm converting are my own, and once they are moved over to git the svn repository will no longer be maintained and will likely be deleted completely from my system.

So can git-svn be used for this? Are there options to git-svn to just use the tool as a one-way converter? What are other people doing in this case?

I suppose I could simply export my svn repositories without version history and just git init, but I'd rather not lose my change history if there's a convenient way to do that.

Converting svn to a git master via git-svn is a two step process. First, you import from svn into an interim git repository. Second, you clone that interim repository using the --bare command to break the link to the original svn repository.

The process I wrote up for our internal use goes something like this:

GiT Version Control System for Rails Projects To Import an Existing Subversion Project into GiT

1. Set up a directory structure to hold the GiT repositories. This structure is very important if these are to be publicly published. It may be desirable to have a master git repository holding many sub-projects as submodules. This provides a great deal of flexibility with respect to managing large scale development spread over many distinct activities. An example of a suggested structure is:

/var/data/vcs-git `-- hll     `-- git-svn.users

In this example, the root of the master repository is /var/data/vcs-git/hll and it contains but one file whose contents are discussed below.

2. Switch to the master directory and create an authors file that maps svn committor userids to a GiT user and eMail address.

$ vi git-svn.users svn-userid = A. Git User <userga@mydomain.tld>

3. Use git-svn to clone the existing Subversion repository. The clone option will create a subdirectory for the project within the master directory. If the Subversion repository was not set using the recommended directory structure (*--stdlayout*) of ./project_name/trunk, ./project_name/branches, and ./project_name/tags then you may have to use the options *-T*, *-b* and *-t* to specify where these project components reside within the repository. You must provide the checkout protocol and uri to the Subversion project as the final argument. If you ONLY want the trunk or a specific branch or tag in the new GiT repository then you must specify it in the URI (note the convention of '_tmp' suffix for a staging repository is only that, a convention):

$ git-svn clone --authors-file=git-svn.users --no-metadata \   --stdlayout https://svn.harte-lyne.ca/&lt;master\-project&gt;/&lt;sub\-project&gt;\[/trunk\] <target/directory/filename>_tmp $

4. If all of the arguments are correct and all of the userids in the Subversion repository are mapped properly in the authors file then you will see something like this:

$ git-svn clone --authors-file=git-svn.users --no-metadata https://svn.harte-lyne.ca/hllsystem Initialized empty Git repository in .git/         A trunk/README W: +empty_dir: trunk/HP3K2linux r11 = d97da2382e7c6e11a7107619d96c6214a2437942 (git-svn) W: +empty_dir: trunk/data r12 = 8ce38690b166128b90393a89fcea7ff115987210 (git-svn)         A trunk/HP3K2linux/hll-qpxfr.rb         A trunk/codemodel.rb r13 = 49e3e692f7ddf9750a9a5b7b6cff83dcd6d4e1fa (git-svn)

...

Checked out HEAD:   https://svn.harte-lyne.ca/hllsystem r59

Now create a clean bare clone of this converted repository into our final new master GiT repository (note that the .git suffix is just a local convention):

$ # Now clone from _tmp repository into bare repository $ git-clone --bare --no-metadata <target/directory/filename>_tmp <target/directory/filename>.git $ $ # Perform some housekeeping to keep things sane when working via remote. $ $ git-update-server-info $ $ # This lets members of the vcs group push commits to the master $ chown -R vcs: <target/directory/filename>.git

Note as well: Importing from subversion can take a very long time if the project is large.