Reviving a git-svn clone
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.
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
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. 🙂
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.)
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!
I got the same error as Mateuz, then even trying the update-ref roy mention, get the same error: