5

I did a number of searches, but couldn't find an answer to this question. Apologies if it is a duplicate.

I'd like to know if there are any problems initializing a git repo (for local usage) within an existing svn checkout, but without using git-svn.

Here's my scenario:

  • My team uses svn and is not familiar with git.
  • I'm still learning git; I'm not nearly as familiar with it as I am with svn.
  • I'd like to make use of the powerful local features of git (like branching, stashing, etc).
  • I do not want to learn git-svn at this time (though I plan to in the future).
  • I will be using an svn client exclusively to interact with the repository. (So I clearly understand what I'm doing from the svn side and don't get any strange interactions).

I'm thinking that I would always do svn update and commit from the git master branch. As I work on features, I'd merge to and from master.

Has anyone tried this? Are there any nasty drawbacks or side effects? Tips?

2 Answers 2

6

TL;DR: Yes you can, but it's harder work than just learning git-svn.

I've tried it. The main problem you have is converting svn up operations to Git commits. There are two approaches I've seen:

  1. Add your .svn folder to .gitignore, so you never have Git tracking your Subversion metadata. This means you have Subversion and Git separately tracking your working copy, so any operation on one requires a similar operation on the other.

    Unless you put a lot of thought into how you're going to use the repository, are very comfortable using Subversion merges, branches and switches, and make sure to use those carefully to match up what you're doing with the repository with Git, you'll lose most of the advantages of Git's branching model.

  2. Track your .svn folder with Git. This means that if, for example, you did an svn up and a git commit, then checked out an old Git commit, the Subversion metadata would match up correctly.

    This means you can more easily use Git's branching features, but there's a host of other problems with having Git track Subversion metadata. The primary one (at least for Subversion 1.6, I don't know about 1.7) is that empty folders in a .svn directory are significant, but Git doesn't track empty folders, so they'll be deleted without warning.

I used method 1 for a little while, but found it gave me all the worst bits of both Git and Subversion, with very little advantage, and meant everything operation needed to be done twice to get anything done.

A colleague of mine used method 2 for some time with more luck, but he wrote a whole bunch of helper scripts to enable him to do so. In particular, his scripts would spin through the working copy and fix up any .svn directories that needed empty folders adding. It was a lot of work to set up, but meant he could at least use most of the features of Git. Sadly, I don't have access to the scripts in question.

Having used git-svn for some time, I can vouch for it being easier than either of these options, even as a Git beginner. I'd recommend keeping a Subversion working copy around for the occasions when you need to do something now and don't have time to check the best way to do it with Git, or for the occasions where git-svn is too limited to do what you need it to do. The learning curve for git-svn is, I'd say, not much more difficult than that for regular Git, particularly as you don't need to learn anything about working with a remote Git repository.

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

3 Comments

This was my experience, too. +1 for recommending a separate SVN WC for complex operations beyond your current skill level.
That's a much more complete summary than mine, never even occurred to me to version the .svn folder.
@jordan002: I keep a Subversion working copy not just for stuff beyond your current skill level. There are some Subversion operations that you just can't do with git-svn whatever your skill level, because some Subversion concepts (arbitrary metadata on files/folders, tracking empty folders, tagging/branching subfolders…) just don't have an equivalent in Git.
1

I tried this, it can work. You just need to add SVN related files to your .gitignore and Git related files to svn ignore. A similar question was also asked here, just replace StarTeam with SVN.

There's really not much to learn to get going with git-svn. Your workflow will basically be (rest of article):

  1. create local git repo: git svn clone -s http://svnrepo
  2. get latest from svn: git svn fetch then git svn rebase
  3. make local changes: git add and git commit -m “message”
  4. push to svn: git svn dcommit

repeating steps 2-4 as necessary.

Not a whole lot to learn, and one less tool to worry about.

3 Comments

Yes, I hope to learn git-svn soon; but I may have other svn stuff to do from day to day (like branching, merging, reverse-merging, etc). So it won't just be update and commit. Honestly, I'm just afraid of adopting git-svn and accidentally doing things I didn't intend.
@Allan I understand your hesitation about accidentally doing the wrong thing. I did the same thing at first, ran git and SVN side by side, looking back on it, it wasn't really worth the hassle, but it's very doable. Just tell each tool to ignore the other's files and you should be good to go.
I used git this way, too, basically shadowing the svn repository, while I was getting comfortable with git. It's not an unreasonable way to try it out.

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.