4

We have a new git repo that is acrued from a svn repo. The git repo is now the leading repository where the further development will happen. This repo is a hosted one. The svn repo on the other side will remain as a publishing pipeline to non git users. The question is, how to update the svn repo from time to time from the git repo? I read a lot about git-svn and that one should not use merge etc (see Is git-svn dcommit after merging in git dangerous?). But merges will happen in the git repo and we don't want to restrict the development in the git repo by weird rules (like "only rebase is allowed").

So the question is simply: Is their a best-practice of how to keep a svn repo in sync with a git repo (let's say biweekly). Is it even possible to re-transport changes safely from svn to git (in case one has to apply an emergency fix to the svn repo, so this will happen rarely).

Since the new git repo is a hosted one, there has to be a svn-git repo in the middle acting as a mediator. This repo could be used to "rewire" git-merges into git-rebases or so. It's also perfectly fine is all intermediate git commits are commited to SVN as one blob.

Udo
  • 2,300
  • 1
  • 23
  • 27

2 Answers2

2

I have a slightly different setup: the SVN repo is not cloned from the Git repo.

My Git repo has mainly two branches: master and svn. master is in sync with a remote bare Git repo, svn is linked to a remote SVN repo.

I apply commits from one side to the other using git cherry-pick and have no problems with rebasing and merging.

I tried merging master into svn before but always ended up with endless conflict resolving sessions. When just using cherry-picking, life is much easier.

To get svn commits into my master, I do the following:

First, get both branches in sync with their upstream:

git checkout svn
git svn rebase

git checkout master
git pull

Then (while being on master):

gitk svn

This brings up the gitk window where I select the commits to be transferred from svn to master. Then, I apply the commits to my remote using git push.

To get the changes from master to svn, I git checkout svn and then start gitk master. Once again, I select the commits to be transferred and when done, git svn dcommit pushes the commits to the SVN server.

Simple and painless.

eckes
  • 64,417
  • 29
  • 168
  • 201
  • sounds really interessting - gitk the "transport tool" ;-) I will give this a chance! – Udo Aug 10 '11 at 09:36
  • @Udo: you could of course use also the command line and `git cherry-pick`, but I find the GUI more handy for that. If you're using TortoiseGit, you could even select several commits at once to pick. – eckes Aug 10 '11 at 09:45
1

You can do any merge you want in your Git repo, provided you don't rebase the branch you are dcommit'ing back to SVN.
As long as you don't rewrite any history in that branch, you are free to manage your Git repo workflow as you want.

So a best practice would be to minimize the number of branches in sync with your SVN repo, in order to facilitate the management of those "public" branches ("public" as in visible to all git users and to all svn users).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250