Sunday, February 8, 2009

git-svn and submodules

As of Jan 2009 git-svn does NOT work with submodules. There is no good way to map submodules to svn and the perl script that implements git-svn just bombs when doing git svn dcommit. My exact error was similar to:

952bee47201e87b0b0e851bcbe6c8940d429cda0 doesn't exist in the repository at /usr/local/git/libexec/git-core/git-svn line 3787
Failed to read object 952bee47201e87b0b0e851bcbe6c8940d429cda0 at /usr/local/git/libexec/git-core/git-svn line 480


In my case the submodule was created indirectly because of the script/plugin install in Rails. I went ahead and dug myself in an even bigger hole:

  • I deleted the .submodules file
  • I deleted the content of the submodule itself
  • I used a tar file instead to install the plugin.
  • I generated a new commit
  • the HEAD of my repository became a valid git svn commit


Do NOT do the above. Git svn goes back and translates each of your commits. Just cleaning up the HEAD is not good enough because git svn still bombs on the old commit. You need to go back and
rewrite history. If you did not dug yourself in a bigger hole, as I did, you should be able to use git commit --amend. Otherwise you need to do something like the following:

$ git tag bad mywork~5
$ git checkout bad
$ # make changes here and update the index
$ git commit --amend
$ git rebase --onto HEAD bad mywork


Amazingly the above works, although maybe not from the first time :-) With git and git svn is it REALLY worthwhile reading the documentation. For example another gotcha is that you should not merge too much on the git side of things. Read the CAVEATS under the git svn docs.

2 comments:

Greg Fleming said...

Thanks, this got me out of a jam today.

Grubb said...

This definitely got me pointed in the right direction, thank you. I used a slightly different technique, though. I explain a little better here -

http://ignoredbydinosaurs.com/2011/06/quick-trip-panic-room