9

I just got this wacky (stupid?) idea in my head, where I thought of tracking the same folder (project) with both Git and Subversion at the same time; that is the folder/project will have both .svn and .git directories.

I didn't find anything relevant in my searches, so that's why I am throwing the idea here to assess its pros and cons (if any). What I am probably looking for is: Why this strategy can't or shouldn't be used?

Q: Why would I want to do this?

We already have a Subversion repo on the network, with over 1 year of history + svn:externals + linked to bug tracking + hooks. But I want to have the flexibility of a DVCS, such as Git, so that we don't have to be connected to the network to commit our work; so that we can work remotely as well.

Q: But I can use git svn!

Unfortunately, Git svn doesn't support svn:externals. And git submodules are not the same as svn:externals.

Q: What could be achieved with this combination?

Flexibility of Git: code can be edited and committed locally without being connected to the network; also, pushing the repo to production or staging server or to a colleague would be a piece of cake.

Centralization and external repo utilization of SVN: with effective utilization of SVN:externals, we will be saving ourselves a lot of work, and then the developers are already familiar with SVN.

Ideally, I would like to make a complete switch to Git eventually, but for now, because svn:externals makes it super-easy to integrate external repos, keeping subversion intact makes sense.

3
  • 1
    "Why would I want to do this?" You can import the SVN-history and then only use git Commented Jan 24, 2013 at 12:11
  • 1
    The OP says that this is not feasable at the moment: "We [...] have a Subversion repo on the network with [...] svn:externals + linked to bug tracking + hooks" Commented Jan 24, 2013 at 12:14
  • Possible duplicate: Using git within an svn checkout? (without git-svn) Commented Jan 24, 2013 at 17:32

3 Answers 3

7

This strategy will absolutely work; I've used it, albeit fairly briefly, and I know other developers in my company have used it for longer periods. That doesn't mean it's easy, however.

You'll find you need to do a lot of work to keep Subversion and Git in sync. As a simple example: when you do an svn update, you'll also need to do a git commit -a or similar, else Git will think your working copy has a load of changes that Subversion knows are up-to-date with the remote repository.

This gets much more complicated if you need to svn update -r to see an old revision for some reason, or try an svn switch, etc.

Depending on whether you have Git track your .svn directory, you'll hit other problems. If you don't (ie, you put .svn in your .gitignore file or similar), you'll find it much harder to use Git's branching features. Consider the following workflow:

  1. Create a Git branch to work on a feature.
  2. There's a recently checked in bug in the Subversion repository you need to fix! Switch back to your main Git branch, svn up and git commit, so you have the latest code, fix the bug, git commit and svn commit it.
  3. Checkout your Git feature branch again. Since this is based off a different Subversion revision, Subversion now thinks there's a load of changes in the working copy.

Alternatively, you can have Git track the .svn directory. This avoids the above problem – when you checked out the feature branch again at step 3, you'd also checkout the Subversion metadata from that time, so Subversion knows the correct revisions that everything's based off.

Sadly, Subversion was never designed to be used this way. In Subversion 1.6 (I don't know about 1.7), the .svn directories may contain significant empty folders. Git doesn't track empty folders, so these can be lost between Git operations, breaking the Subversion working copy. I know one developer who wrote a bunch of scripts to fix up such mangled .svn directories, but that's not trivial, and very fragile.

Sign up to request clarification or add additional context in comments.

Comments

2

Git and Svn can live in a directory quite easily. In .gitignore ignore all .svn directories, in svn ignore .git directory. I have used it before, until I realised I do not need SVN anymore.

Comments

1

I think you wouldn't get any conflicts, but your SVN repository wouldn't contain the commits of the GIT repository.

Example:

While offline, a developer performs 5 commits with descriptive commit messages in GIT.
Now, SVN comes back online and he wants to save his changes to SVN. He would now either do a single commit with a less descriptive message or he would have to repeat the commits he made into git by resetting his working copy to those specific commits and committing each of them to SVN.

2 Comments

But isn't this problem inherent to Subversion anyway? With an offline SVN repo (without any Git combination), one would still have to commit all the changes at once when back online, or, worse, wait till one is back online and then start working.
@Sawant: Indeed. I just wanted to make clear that adding GIT to the mix wouldn't change that.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.