Skip to content

Instantly share code, notes, and snippets.

@nbouherrou
Last active October 21, 2019 14:43
Show Gist options
  • Save nbouherrou/cc51baa630f825e6435e to your computer and use it in GitHub Desktop.
Save nbouherrou/cc51baa630f825e6435e to your computer and use it in GitHub Desktop.
Migrate to Git from SVN

Migrate to Git from SVN (Windows)

1. Prepare your environment for the migration

Step 00 : Download the migration script

svn-migration-scripts.jar 

Here : https://bitbucket.org/atlassian/svn-migration-scripts/downloads

To make sure you have the Java Runtime Environment, Git, Subversion, and the git-svn utility installed. Open a command prompt and run the following:

java -jar ~/svn-migration-scripts.jar verify

This will display an error message in the console if you don’t have the necessary programs for the migration process. Make sure that any missing software is installed before moving on. If you get a warning about being unable to determine a version, run :

SET LANG=C

Step 01 : Extract the author information

Create a directory on your local machine called ~/GitMigration. This is where you will perform the conversion.

SVN only records the username of the author for each revision. Git, however, stores the full name and email address of the author. This means that you need to create a text file that maps SVN usernames to their Git counterparts.

Run the following commands to automatically generate this text file:

cd ~/GitMigration 
java -jar ~/svn-migration-scripts.jar authors <svn-repo> > authors.txt

This creates a text file called authors.txt that contains the username of every author in the SVN repository along with a generated name and email address. It should look something like this:

j.doe = j.doe <j.doe@mycompany.com> 
m.smith = m.smith <m.smith@mycompany.com> 

Change the portion to the right of the equal sign to the full name and email address of the corresponding user. For example, you might change the above authors to:

j.doe = John Doe <john.doe@atlassian.com>
 m.smith = Mary Smith <mary.smith@atlassian.com>

Now you’re ready to import your SVN history into a new Git repository. The next phase explains how this conversion works.

###2. Convert the SVN repository to a local Git repository. The next step in the migration from SVN to Git is to import the contents of the SVN repository into a new Git repository.

Step 02 : Clone the SVN repository

*If your SVN project uses the standard /trunk, /branches, and /tags directory layout, you can use :

cd ~/GitMigration 
git svn clone --stdlayout --authors-file=authors.txt <svn-repo>/<project> <git-repo-name>

*If your SVN repository doesn’t have a standard layout, you need to provide the locations of your trunk, branches, and tags using the --trunk, --branches, and --tags command line options.

cd ~/GitMigration 
git svn clone --trunk=/trunk --branches=/branches 
 --branches=/bugfixes --tags=/tags --authors-file=authors.txt 
 <svn-repo>/<project> <git-repo-name>

If you have an "svn error validating server certificate" FIX (for windows) :

  • Delete : C:\Users\"USERNAME"\AppData\Roaming\Subversion\auth\svn.ssl.server
  • Open the command prompt and run : svn list https:...
  • Accept certficate permanently by entering : p

Step 03 : Clean the new Git repository

To see what can be cleaned up, run the following command in ~/GitMigration/:

java -Dfile.encoding=utf-8 -jar ~/svn-migration-scripts.jar clean-git

This will output all of the changes the script wants to make, but it won’t actually make any of them. To execute these changes, you need to use the --force option, like so:

java -Dfile.encoding=utf-8 -jar ~/svn-migration-scripts.jar clean-git --force

You should now see all of your SVN branches in the git branch output, along with your SVN tags in the git tag output. This means that you’ve successfully converted your SVN project to a Git repository.

###3. Synchronize

Step 04 : Update the authors file

git config svn.authorsfile <path-to-authors-file>

Step 05 : Fetch the new SVN commits

git svn fetch

Step 06 : Synchronize with the fetched commits

java -Dfile.encoding=utf-8 -jar ~/svn-migration-scripts.jar sync-rebase

Step 07 : Clean up the Git repo

java -Dfile.encoding=utf-8 -jar ~/svn-migration-scripts.jar clean-git 
 --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment