4

I have cloned an existing SVN project via git svn clone with no problem so far, but in the mean time I have created a branch in Git only (not in SVN) and now i would like to synchronize this branch back to an SVN branch (not the trunk).

I have created the branch a little time ago. Is it possible to get back the information stored on that Git branch into SVN?

madth3
  • 7,275
  • 12
  • 50
  • 74
khmarbaise
  • 92,914
  • 28
  • 189
  • 235

1 Answers1

5

You can create a new branch in Subversion using git svn branch. You might want to look at the example in this answer:

In particular, a good tip in the linked tutorial is to use the --dry-run option to svn dcommit to check that when you run the command for real, it'll be pushing to the right branch.

The Pro Git book has a clearer description of how git svn dcommit decides which svn branch to update. It sounds to me as if you should:

  • Create a new svn branch using git svn branch new-experiment
  • Create a local branch to track remotes/new-experiment with git checkout --track -b new-experiment remotes/new-experiment
  • Rebase the changes from your old git topic branch (let's suppose it's called experiment) onto new-experiment:

     git checkout experiment
     git branch original-experiment
     git rebase new-experiment
     git checkout new-experiment
     git merge experiment
    
  • Try git svn dcommit --dry-run to check that the right subversion branch will be updated
  • If so, do git svn dcommit
Community
  • 1
  • 1
Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • I want to commit the changes i made on the Git branch into a Subversion branch and NOT to the trunk. If i would like to get those changes to the trunk i can simply do a merge before. – khmarbaise Mar 11 '11 at 08:39
  • That wasn't at all clear from your question. I'll update my answer. – Mark Longair Mar 11 '11 at 08:45
  • @khmarbaise: OK, I've finished updating my answer now - I hope that's more clear. I'm suggesting rebasing rather than merging so that you don't just end up with one merge commit in your subversion branch. – Mark Longair Mar 11 '11 at 09:29
  • I got the error `'remotes/my-branch' is not a commit and a branch 'my-branch' cannot be created from it.` I had to do `git branch -r` to see the actual name. – nupanick Jan 16 '19 at 02:47