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/frozen", 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 indicate 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 set up 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 names
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 newly 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
Best Answer
There are several methods Subversion uses to talk to the Subversion server:
So, the first thing we need to know is how are you talking to your Subversion repository? Did you set it up? If you did, are you running
svnserve
in order to act as a server? Or, did you configure your Apache httpd web server to act as the Subversion repository server? If you didn't set it up, who did?Let's go through the basics:
File Access
You created the Subversion repository in /usr/share/svn/repository using the
svnadmin create
command. You didn't do anything else. In that case, you would access your repository as:Note that the URL protocol is
file://
and notsvn://
.SVNSERVE Access
Let's say that your repository sits on machine alpha, and there's only a single repository on alpha
The format for the URL is:
Note that the protocol is
svn://
and the first thing after the protocol is the machine name. Thesvnserve
is a simple, easy to setup, and fast server for Subversion repositories. I use it even if I could usefile://
just because I don't have to keep giving the full path name each time.If you setup your own Subversion repository, you can use the
svnserve
to run it. It uses port 3690 by default, and only a singlesvnserve
instance can run on a machine using that port (you can change the port, but it's messy and I don't want to go into now).To use the svnserve server, you need to do a few very minor things:
svnserve.conf
File: Under your repository is a directory calledconf
. In this directory is a file calledsvnserve.conf
. You need to find the line that begins withpassed
and remove the pound signs (aka sharps or octothorps) in front of the line: It's around line #20.Just change:
to:
passwd file:** In the same directory as the
svnserve.conffile is another file called
passwd. Edit this file, to include an account for you. There's two examples in the file for
harryand
sally`. Create one for you. This will be your user name (no spaces) and your password. When you checkout or commit files in Subversion, you'll use this.http Access
You can setup an Apache httpd web server (the most popular web server on the Internet) to also be used as a Subversion server. It's a complex process, and I'm not going into here. However, if someone has set it up for you, the URL would be split into several parts:
http://
protocol declarationLet's say the machine is named alpha, and you want to checkout from the
foo
project's repository:I highly suggest you edit your question and include some more details. For example, where does your Subversion repository reside? Is it on your current system? Did you setup your Subversion repository, or did an administrator do it for you? Show us the exact command and error message you're getting too.
Otherwise, your question will probably be closed. See the Stackoverflow FAQ for more information.