2

Some open source projects I am interested in have been tracked using Subversion rather than Git. I know nothing about Subversion. Recenly, I have learnt about Git and SourceTree and am very familiar with these two things.

Now the question is, what options do I have to view the Subversion project history since SourceTree cannot be used for this? I want to be able to clone the repository to view the history and also make changes. I don't think there is a way to convert the subversion information into Git information.

Giacomo1968
  • 58,727
gyuunyuu
  • 243

1 Answers1

2

Yes you can if you use svn2git.

“I don't think there is a way to convert the subversion information into Git information.”

Nope… Yes you can! Just use the snv2git Ruby GEM:

svn2git is a tiny utility for migrating projects from Subversion to Git while keeping the trunk, branches and tags where they should be. It uses git-svn to clone an svn repository and does some clean-up to make sure branches and tags are imported in a meaningful way, and that the code checked into master ends up being what's currently in your svn trunk rather than whichever svn branch your last commit was in.”

Here is how I use it: There are two initial major steps and one after-conversion step:

  1. Map the authors from Subversion to Git format.
  2. Convert the Subversion repo to a Git repo.
  3. Checkout the trunk branch in the converted Git repo.

Step 1: Prepare the Subversion author list map file for Git usage.

While the Subversion repository to Git repository process is pretty clean, the one thing you need to do before you start is to map the user names from the Subversion repository to something that matches users in the Git repository. Here is how you would do this.

First, in the Subversion cloned directory, run this command to get a list of authors connected to the Subversion repository:

svn log --xml | grep author | sort -u | perl -pe 's/.*>(.*?)<.*/$1 = /'

Take that output and place it in file called svn-authors.txt like this:

userone
usertwo

And edit that file manually to map those users to their Git equivalents like this:

userone = User One <userone@example.com>
usertwo = User Two <usertwo@example.com>

Save that svn-authors.txt and move onto the next steps.

Step Two: Create the new Git repository and run the conversion.

Create a directory of the new Git repository:

mkdir Some-Project

Go into that Some-Project directory:

cd Some-Project

Now, create a Git repository in that directory:

git init

Make note of the source Subversion repository URL:

https://svn.example.com/repo/Some-Project/trunk/

And run svn2git within the Git repository directory to let the magic begin:

svn2git https://svn.example.com/repo/Some-Project/trunk/ --authors svn-authors.txt --verbose --rootistrunk

Note the placement of the Subversion repository URL and the svn-authors.txt text file in that svn2git.

Step Three: Post-conversion cleanup.

Now checkout the trunk like this:

git checkout trunk

The directory should be filled up with Subversion content now. Tweak and adjust content as needed.

Giacomo1968
  • 58,727