views:

9380

answers:

9

I read 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.

+14  A: 

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:

$ man git-svn
jfm3
I want to migrate my own repos. from SVN to Git. One time only. After I do it, I'll shut down SVN server and, hopefully, never start it again.BTw, tried your command:Can't locate Error.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.8 ...etc.Looks like Git in Slackware 12.1 is broken.
Milan Babuškov
Use CPAN to install the Error module, I think. You can use git-svn for a one-time migration.
emk
@Milan: I get this error when the subversion perl bindings are not installed.
Denis Bueno
+19  A: 

Cleanly Migrate Your Subversion Repository To a GIT Repository.

eed3si9n
Link does not work. Someone please update this.
WarmWaffles
webarchive link is also broken: I guess this is the article: http://www.jonmaddox.com/2008/03/05/cleanly-migrate-your-subversion-repository-to-a-git-repository/
Teun D
+1  A: 

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
Denis Bueno
+8  A: 

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 (not sure if this works on Windows... works on OSX and Linux)

gitk

When you've got your svn repo cloned locally, you may want to push it to a centralized git repo for easier collaboration. First create your empty remote repo (maybe on GitHub?)

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

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

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

After that, you may be interested in tyring out my very own git_remote_branch tool, which helps dealing with remote branches :-)

First explanatory post

Follow-up for the most recent version

webmat
Huge Thanks for this post it's been extremely useful in helping me migrate my SVN repo's to git.
Naz
+1  A: 

could someone also tag this with git-svn as well, since it belongs there too

Gregg Lind
Sure, it's done.
Milan Babuškov
+2  A: 

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

webmat
+1  A: 

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

Effectively using Git with Subversion is a gentle introduction to git-svn. For existing SVN repos, git-svn makes this super easy. If you're starting a new repo, it's vastly easier to first create an empty SVN repository 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 commit history.

burkestar
+1  A: 

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

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

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

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

A this command will create a new git repo in dest_dir-tmp and start pulling the SVN repo.

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

cd dest_dir
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 repo, you want to create a local branch for each one manually. 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

Finally, clone your GIT-SVN repo into a clean git repo:

git clone dest_dir-tmp dest_dir
rm -rf dest_dir-tmp
Casey