Skip to content

Instantly share code, notes, and snippets.

@DineshSolanki
Created September 6, 2023 12:45
Show Gist options
  • Save DineshSolanki/e159a3a639d44ce5fc61e703c53ccf86 to your computer and use it in GitHub Desktop.
Save DineshSolanki/e159a3a639d44ce5fc61e703c53ccf86 to your computer and use it in GitHub Desktop.
SVN 2 GIT

Here is a visually appealing guide for migrating from SVN to Git:

Migrate SVN to Git

1. Generate authors file

Navigate to SVN repo directory:

cd /path/to/svn/repo

Generate authors file:

svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > users.txt

This will create a users.txt file with SVN authors mapped to Git format.

2. Prepare Git repo

Create new folder for Git repo:

mkdir new-git-repo
cd new-git-repo

Copy users.txt file there:

cp /path/to/svn/repo/users.txt .

3. Clone SVN into Git

Clone SVN repo into new Git repo folder:

git svn clone --no-metadata -A users.txt https://url/to/svn/repo

This will clone the SVN repo and authors into Git.

4. Add Git remote

Add new empty Git repo as remote:

git remote add mirror https://url/to/new/git/repo.git 

5. Push to Git

Push local Git repo to new Git remote:

git push --set-upstream mirror master

That's it! The SVN repo is now migrated to a new Git remote.

Here is the FAQ in Markdown format:

Frequently Asked Questions

What is the overall process for migrating from SVN to Git?

The key steps are:

  1. Generate an authors mapping file from SVN
  2. Create a new Git repo and copy the authors file there
  3. Clone the SVN repo into Git using the authors file
  4. Add the new Git repo as a remote
  5. Push the local Git repo to the new remote

Why generate an authors file?

Git stores committer information differently than SVN. The authors file maps SVN authors to Git format so the commit history and authors are preserved.

What is the most common error when generating the authors file?

The command to generate the authors file can fail if the SVN usernames have special characters. Double check the format of the usernames and edit the file manually if needed.

What happens if I don't use the authors file when cloning SVN to Git?

The commit history will lose the authorship information and all commits will be authored by the user performing the migration.

When adding the Git remote, what protocol should I use?

Use SSH rather than HTTPS if you have access. SSH allows pushing without credentials.

What if I run into issues pushing to the Git remote?

Make sure you have permissions to push to the new Git repo. Check that the remote URL and branch name are correct. Use -f if you need to force push.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment