32

I work with software that is kept in svn for version control. I would like to use git (git-svn) however the software requires lots of setup and configuration before it can be used. There are tools that take care of all of the setup, including checking out all the code via svn.

All the documentation for git-svn (I've been able to find) requires a fresh checkout, using git-svn.

Is there a way to convert an existing svn checkout so it can use git-svn?

Zoe
  • 27,060
  • 21
  • 118
  • 148
Jachin
  • 2,025
  • 2
  • 19
  • 26

5 Answers5

14

No. A git-svn clone converts the entire repository into git. SVN checkouts do not have the entire repository and so cannot be cloned from. This is the primary advantage of switching from SVN or CVS to a distributed system (like git).

singpolyma
  • 10,999
  • 5
  • 47
  • 71
  • 1
    I don't care about all the history though, just the state it is in when it got checked out of svn, and future changes on the svn branch (so what I'd get from calling git-svn rebase) – Jachin May 05 '09 at 21:16
  • 3
    That's not how git works. DVCS is "distributed" because every clone is a full copy of the repository. That's the whole point. – singpolyma May 05 '09 at 21:53
  • 1
    Again you see the clever people explaining, how much should you care about history... I do care about history, but only FROM NOW ON, suppose the history is trashed with tons of unneccessary binary files (no problem in SVN), and only recently the working tree is free of such burdens, svn:externals, etc. – Tomasz Gandor Oct 21 '14 at 11:16
11

You could do something like this:

  1. Do a full clone of your SVN tree using git-svn, to a temporary directory. Make sure you use the exact same revision as your existing checkout.
  2. Move the ".git" folder from the top level of the git-svn checkout into the top level of the SVN checkout.
  3. Then you'll either need to tell Git to ignore the ".svn" directories, or you can delete them all.
  4. Delete the git-svn checkout.
  5. There, now you can manipulate your existing files with Git and git-svn.
  6. Do a "git status" and hope that it says there are no changes.
andy
  • 18,005
  • 9
  • 30
  • 27
  • I haven't got it completely working how I want it, but this sort of strategy seems like it will work. – Jachin May 18 '09 at 19:41
  • 3
    Is there any way to accomplish that WITHOUT having access to the svn repo? I have currently no way of accessing the repo, all I have is an untouched working copy at the last revision. I hoped that maybe git svn fetch -r N, with N being the revision of my working copy, might somehow be persuaded to use the working copy's content to fetch the needed information... – Ole Aug 27 '09 at 08:38
4

I assume you probably want to keep the history. However, in case you (or anyone else who stumbles on this page) doesn't need history, you can use the "export" feature as explained here: https://stackoverflow.com/a/419475/2437521.

Community
  • 1
  • 1
C. Tewalt
  • 2,271
  • 2
  • 30
  • 49
1

Another way to do this, which does not modify the original Subversion working copy and does not require you to copy it, is using a patch:

  1. Do a full clone of your Subversion tree using git-svn, to a new directory which will be the Git repository. Make sure you use the exact same revision as your existing checkout. You can use git reset --hard :/r<revision> to force it to be the same revision after cloning, where <revision> is the revision that the Subversion working copy is updated to (see this using svn info there).
  2. cd to your Subversion working copy.
  3. Use svn status to make sure all new files are marked with A (or use svn add to add them), and all deleted files are marked with D (or use svn rm to delete them).
  4. Run svn diff >patch.diff to create a patch file.
  5. Copy patch.diff to the top of the Git repository created before.
  6. cd to the top of the Git repository created before.
  7. Run git apply -p0 patch.diff to apply the patch on the working tree of the Git repository.

Now you can go through the changes using git status, and git add/git commit them to save them in your local repository.

Daniel Hershcovich
  • 3,751
  • 2
  • 30
  • 35
0

This seems to work:

(Warning: I have not tested this enough. Make a backup before you try.)

  1. Initialize git-svn with the current SVN URL:

    git svn init $(svn info --show-item=url)
    
  2. Fetch SVN HEAD for Git. This unfortunately downloads HEAD instead of using the local checkout, but it's only downloaded into .git.

    git svn fetch -r HEAD
    

    git-svn fetch will complain with something like

    error: Untracked working tree file '' would be overwritten by merge.

    But the current commit will correspond with SVN HEAD. The working directory will be kept in place.

  3. The staging area now contains SVN HEAD; unstage it.

    git reset HEAD -- .
    

The state of the repository should now be the same as if you did git svn clone -r HEAD <URL> then applied your changes on top.

Kisaragi Hiu
  • 202
  • 2
  • 8