0

Where I work we use Git for our current projects, but we have a few legacy projects on SVN. I'm looking at converting a couple of large legacy projects (26,000+ commits) from SVN to Git.

However, the issue I have is that we also wish to keep the SVN repositories. The reason for this is that deployments are handled by updating/switching SVN checkouts existing on client environments: Updating our deployment scripts to use Git, reconfiguring all of our clients' environments to use Git checkouts etc. is a very big task; We think that the benefits of switching to Git (having a single VCS with a consistent pull-request/code-review process for all projects) are sadly outweighed by the costs involved in doing this.

So as a compromise, we'd like to have a workflow that looks like this:

  • Github pull request.
  • Merge pull request to master.
  • Update SVN with latest code in Git master branch.
  • Update SVN checkout on client server.

SVN would only be written to as part of this process (i.e. we'd only need to synchronise in one direction: Git to SVN).

I've seen the git svn command and https://github.com/nirvdrum/svn2git and a colleague has successfully generated Git repositories from SVN using this. However, I wasn't able to easily get commits back into SVN after checking out the repository (from Github) that he generated. We'd originally planned to use git svn dcommit to do this, but, as I understand it, this command essentially requires the Git repository to be synchronised with SVN. git svn dcommit does not seem to work with a fresh checkout of the Git repository: I believe this is because git svn init and git svn fetch need to have been run before dcommit will work (please correct me if I'm wrong).

The problem with this is that git svn fetch takes days to run on repositories this large. Any developer wishing to perform a release would need to have a Git checkout synchronised with SVN, which doesn't seem like a reasonable option, particularly when it is considered that these are legacy projects that will be worked on, but infrequently.

As an alternative to dcommit, I've written a script to checkout the SVN and Git repositories, delete the contents of the SVN checkout and replace it with the contents of the Git repository, then commit back to SVN. The atomicity of the commits and the history for new commits would not be copied to SVN using this approach, but that is not a concern. The history would still exist in Git: As long as SVN reflects the latest state of the files in Git, it's not a problem. This almost seems to work, but there are some issues with this script generating large whitespace commits (for line-ending changes) and deleting empty directories from SVN (Git does not support committing empty directories like SVN does).

Is there a better way to handle this workflow? If the script is the way to go, can you suggest any configuration options to make this process run smoothly? I'm thinking SVN's eol-style and Git's core.autocrlf settings may be able to be used to work around this (possibly in combination with a tool like dos2unix), but I can't quite work out the best approach. I may be able to fix the empty directories issue with .gitkeep "placeholder" files, but this will obviously require the code to be tested to ensure that these files can exist without causing problems: Is there another way around this?

Any advice appreciated.

1
  • A dirty way to work around the problem of doing a fresh git svn fetch by every single developer could be to share once fetched copy (potentially updating it from time). Another option could be to create a simple shared (web) tool that would squash changes from git and push to svn. But the path of tuning your sync script (fixing EOLs and directories) looks the most reasonable to me. Nov 18, 2014 at 22:04

1 Answer 1

0

I haven't gotten to the stage of trying to commit back to SVN yet (and I'm quietly dreading EOL issues when I do so), but I can tell you a method of handling the git checkout so that it doesn't take days on a large repository.

The trick is to limit the history to the minimum that you need. At the time you're wanting to create the git repository from the SVN one, check the SVN log for a recent revision on the branch you want. This can either be the HEAD revision if you don't care about history at all, or some revision in the recent past (typically a few days).

git svn clone -r nnn:HEAD --prefix=origin/ --username=USERNAME svn://server/trunk/

The key part is to put that revision number in the nnn:HEAD fragment. This will import the current state of all files at that revision into git (flattening history), and then record each subsequent SVN change as a separate git revision as normal. This may still take an hour or two for a very large repository or if you've chosen a large revision range, but it shouldn't be days any more.

The downside of course is that you've only got the one branch (or trunk) and only limited history, so if you want to see further back you have to use the SVN repo browser, and if you want to work on a different SVN branch then you have to repeat this process (there's probably a way to selectively splice additional SVN branches in but I haven't looked into it). But you can create as many local git branches as you want, so it still gets you a long way.

Once you have this initial base, you can use git svn fetch to fetch new SVN revisions and git svn rebase to apply these new revisions to your local git branches. TortoiseGit makes this fairly painless if you're working on Windows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.