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?
You could do something like this:
- 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.
- Move the ".git" folder from the top level of the git-svn checkout into the top level of the SVN checkout.
- Then you'll either need to tell Git to ignore the ".svn" directories, or you can delete them all.
- Delete the git-svn checkout.
- There, now you can manipulate your existing files with Git and git-svn.
- Do a "git status" and hope that it says there are no changes.
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).
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.
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:
- 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).
cd
to your Subversion working copy.
- 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).
- Run
svn diff >patch.diff
to create a patch file.
- Copy
patch.diff
to the top of the Git repository created before.
cd
to the top of the Git repository created before.
- 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.