Moving from SVN to Git
The goal of this section is only provide an overview of the options available to migrate from SVN to Git. The complexity and amount of time it takes to migrate from SVN to Git will depend on the size of your repository and the amount of users you have.
There are two ways to approach moving to Git from Subversion.
- Bridging
- Fully Migrating
Let’s look at each one in a bit more details.
Bridging Git to SVN #
Bridging Git to SVN means running a Git repository locally while pushing your changes to an SVN repository. This setup allows you to work with Git commands locally while keeping your repository as SVN. It’s a client tool (Git) that interacts with a SVN server.
However, you are limited to what you can do. All of your changes and operations need to be translated to SVN commits.
To get started with bridging Git to SVN, you first need to clone the remote SVN repository and import it as a local Git repository. You do that using:
$ git svn clone <repository URL> project_folder
After making changes, you still use git-commit
to commit your changes:
$ git commit -am "my new changes"
However, this commit is still only in your local Git repository. We need to push it up to the SVN repository. To do that we need to use a special git-svn
bridge command called dcommit
:
$ git svn dcommit
This creates an SVN commit for each Git commit and then rewrites the local commit.
If you need to pull down changes from the SVN repository in to your local Git repository, you can do that using rebase. But it’s a special version of rebase using the git-svn
bridge.
$ git svn rebase
This pulls down the commits from SVN and replays them, saving them as git commits.
For full documentation on how to bridge Git to SVN, please refer to the official Git documentation.
Migrating An SVN Repository to Git #
You may want to move over to Git completely and not bother with the bridge commnds. To do that, you need to migrate the repository to a local Git repository using the git svn clone
command. This is the same command we used in the first step of bridging Git to SVN.
$ git svn clone <url> project_folder
The time it will take to clone the SVN repository will depend on the size of your SVN repository. After you clone the repository you should then push to a remote, assuming that’s the workflow you want to build for your team.
One note on migrating: the official documentation recommends that you first export your SVN users and include them as part of the clone command. This will result is cleaner commit data. Refer to the official documentation for more information on the exact steps to do this, including how to migrate remotes and tags.