Rip's Domain

Reviving a git-svn clone

Posted in Git by rip747 on June 17, 2009

Compiled by following: http://osdir.com/ml/git/2009-04/msg01781.html

Thank you Martin Krafft @ http://madduck.net/, you saved my ass and I don’t even know you :)

Here’s the problem. I’m mirroring the CFWheels SVN repo (please migrate to github) using git and github. Last week my cygwin installation took a dive and in the midst of trying to fix it, I screwed up my local git repo used to do this mirror (completely my fault and not git’s or cygwin’s. Yes, I’m an idiot).

Anywho, I finally got everything up and running with cygwin, but now came the problem of getting the mirror working again. In the past to accomplish this, I actually did a forced push to the master branch on the mirror. It was OK since noone at the time had forked the mirror so it didn’t hurt anything. But now we have some people who have forked the mirror, so this isn’t an option for me any more. I actually had to figure out how to fix this.

After A LOT of searching and reading here is how I revived my git mirror of the CFWheels SVN repo. It turned out to be 4 simple command in git:

$ mkdir cfwheels
$ cd cfwheels
$ git clone git@github.com:rip747/cfwheels.git
$ git svn init https://cfwheels.googlecode.com/svn/trunk
$ git update-ref refs/remotes/git-svn refs/remotes/origin/master
$ git svn rebase

Now to explain each line (so I don’t forget):

$ mkdir cfwheels
$ cd cfwheels

Obviously I’m making a directory on my machine called cfwheels and switching to it (basic stuff)

$ git clone git@github.com:rip747/cfwheels.git

Here I’m cloning the svn mirror repo from github.

$ git svn init https://cfwheels.googlecode.com/svn/trunk

Here I’m creating a reference to the cfwheels repo on googlecode in my local git repo

$ git update-ref refs/remotes/git-svn refs/remotes/origin/master

This is the secret sauce! What I’m doing here is updating the HEAD of the git-svn remote (refs/remotes/git-svn, this is created for you by doing the “git svn init”) to match the HEAD I grabbed from github (refs/remotes/origin/master, again this is created for you by doing the “git clone”).

$ git svn rebase

Now that the two heads match, I’m able to pull the revision information from googlecode. What you’ll see at this point is a mess of lines run on the screen which corresponds to each commit in the svn repo. At the end you should get the following message:

Done rebuilding .git/svn/git-svn/.rev_map.d8ff095c-9719-0410-9cd3-1dd5d13d90f5
Current branch master is up to date.

Hopefully this helps you out. If I missed anything or you have an updated way to do this, please comment below.

About these ads

5 Responses

Subscribe to comments with RSS.

  1. Mateusz Loskot said, on February 16, 2010 at 5:47 pm

    FYI, this solution does not work for me and the git svn rebase throws this message:

    Unable to determine upstream SVN information from working tree history

    It’s also interesting that this solution seems to be not recommended in terms of safety and integrity:

    “For the sake of simplicity and interoperating with SVN, it is recommended that all git-svn users clone, fetch and dcommit directly from the SVN server”

    http://stackoverflow.com/questions/1880405/can-different-git-svn-clones-of-the-same-svn-repository-expect-to-be-able-to-shar/1880487#1880487

  2. rip747 said, on February 16, 2010 at 6:47 pm

    what version of git are you using and can you post the commands that you use. i just use this post the other to revive my local repo yet again after i screwed something up and everything is working great. :)

  3. Roy said, on February 23, 2010 at 9:00 pm

    Try:
    git update-ref refs/remotes/trunk refs/remotes/origin/master

    This worked with git 1.6.6.2 for me. (At least the rebase worked, I haven’t tried to do anything with with cloned repo yet.)

  4. Ted Kulp said, on July 19, 2010 at 9:11 pm

    You guys are life savers. I spent an hour looking for this.

    With this article and Roy’s addition, it worked like a charm. Of course, it made total sense after I read it (and what update-ref does), but I wasn’t sure what git svn was doing under the hood so I never would’ve figured it out on my own.

    Thanks again!

  5. Lantrix said, on October 1, 2010 at 6:27 am

    I got the same error as Mateuz, then even trying the update-ref roy mention, get the same error:

    Unable to determine upstream SVN information from working tree history
    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: