Synchronizing code with two subversion repositories

你。 提交于 2019-11-30 04:13:54

I did this using git svn, with my development done in a git repository. The remote development is done in subversion. I made a git svn clone of the subversion repository, which I push to a real git repository. A cronjob runs "git svn rebase && git push" every now and again to create a git mirror of the subversion repo.

In order to merge the subversion changes, I have 2 remotes in my local git copy - the "local development" origin and the "from subversion mirror" origin. Whenever I feel the need, I can merge changes from the subversion mirror into our development tree. Local changes are not affected, they live apart and don't mess up the svn mirror.

I used gitosis to set up and administer the git repositories. The steps would be something like this (from memory, may be wrong):

# set up the mirror
git svn clone -s $SVN
git remote add origin git@$MACHINE:svnmirror.git
git push
# + cron job to do git svn rebase && git push every N hours/minutes

# set up the local working copy for development
git clone git://$MACHINE/svnmirror.git
# that's an anonymous, read only clone 
# no push to the svn mirror for developers - only cronjob user can push there
git remote add newproject git@$MACHINE:myproject.git
git push newproject
# now do the real deal
git clone git://$MACHINE/myproject.git
# hack hack hack
git push # origin master not needed
git remote add svnmirror git://$MACHINE/svnmirror.git
git merge svnmirror/master
git push

You can have your local repository where you commit your changes, as you already have done. Further you would do a periodic merge from the base repository in order to merge the changes done in the base trunk into your local repository.

The only difficult thing is that you need to keep track of the revisions from which you've already merged from the base repository.

This could look like this:

svn merge -r X:Y baseRepositoryURL // merge from base repo
svn commit                         // commit the changes to local repo
svn merge -r Y:Z baseRepositoryURL // merge from base repo
svn commit                         // commit the changes to local repo

Where X is the revision of your initial checkout, Y is the head revision a the time of the first merge and Z is the head revision a the time of the second merge. You see the pattern. Furthermore it is important that you are in the base directory of your local checkout when issueing the commands.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!