0

I'm an svn user with a requirement to mirror my svn code to a git repository. Users of git will not have access to the svn repository, so the solution cannot rely on checking out the code directly from svn as some kind of external repository.

I'm trying to use git-svn such that I can make changes in svn, then update and sync them to git.

I've cloned the git repo into which I want to sync my svn code, then I do something like:

git svn clone svn+ssh://path/to/my/code --trunk my_module --prefix mirror/

I can see my svn repo being cloned. If I try to switch to the trunk branch like this:

git checkout mirror/trunk

I'm told that I'm in a detached HEAD state (a suitable error message for how I feel right now.)

So my question is, how do I get my locally checked out svn code to upload into a remote git repository. And secondly, how would I go about doing periodic updates of that code?

1 Answer 1

2

mirror/trunk is what git calls a remote tracking branch -- you can't commit to it locally, only fetch to update it, so that's why you're seeing the somewhat dramatic "detached HEAD" message.

You likely were already on the local branch that tracks it by default, master, right after the clone. To get back, just run git checkout master.

To move code from svn into git, first add a remote for the git repository you want your code to end up in:

git remote add public git@...

I would recommend creating a new branch for the svn work to live in, so the git developers don't commit to it and complicate things:

git checkout -b svn-work

Then push it out to the remote you just set up:

git push public svn-work

To keep the git clone up to date, you'll want to run (manually or by cron):

git svn rebase
git push public svn-work

Things get trickier if you want the connection to be bidirectional. The command to move work from git to svn is simple enough:

git svn dcommit

... but there are a lot of caveats in terms of what you can push back into svn; basically, git users will need to ensure that the history of that branch is kept linear, which is not a trivial thing to accomplish.

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

Comments

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.