Jader Dias
Jader Dias

Reputation: 90475

There is any way to synchronize GIT and Subversion repositories?

I want to access a repository using both GIT and SVN clients. A way I imagined to do that is through automatic two-way migration: when a user PUSHes into the GIT repository, it is also COMMITed in the SVN repository and vice-versa.

There is any tool that would help me to do that?

Upvotes: 34

Views: 29668

Answers (6)

mrts
mrts

Reputation: 18925

Our team had exactly the same problem and after a bit of experimentation we managed to come up with a git-Subversion bridge that synchronizes changes between our team git repository and the corporate Subversion repository. Our git usage is transparent to other Subversion users.

The setup is described in more detail at https://github.com/mrts/git-svn-bridge.

We have used this setup in production for more than a year.

I guess the biggest caveat of the setup is that the git repository tracks only SVN trunk (or another single branch), thus other git branches will be squashed into one commit during merge to trunk. For us this is no problem - we use short-lived task branches and consider them to be lightweight, ephemeral "units of work" that can go to mainline in a single chunk - and the branch history is retained in git.

Upvotes: 9

bla
bla

Reputation: 41

I have a bare-git central repos + SVN-git bridge - a repos with git svn, tracking SVN in branch 'current' and tracking GIT repository in branch 'gitcentral'

Then I use post-update hook in central git repos like that:

#!/bin/bash

# Anything inserted into GIT - move it back to SVN

echo
echo '* Pushing data into SVN branch'
cd /home/git/BRIDGE
unset GIT_DIR

# current - svn branch locally and central git branch on project.git repos
# centralgit - unmodified centralgit branch
git fetch /home/git/repositories/project.git/ master:centralgit || (echo "Error while pulling data into bridge repository"; exit 1)
git checkout -b temp centralgit || exit 2
git rebase current || exit 3
git checkout current || exit 4
git reset --hard temp || exit 5
git svn dcommit || exit 6
git branch -D temp || exit 7

echo '* Pushed correctly data into SVN'
exit 0

That's mostly temporal, but works...

Upvotes: 4

iconoclast
iconoclast

Reputation: 22610

You might also want to check out this solution: http://unethicalblogger.com/posts/2008/10/git_back_subversion_mostly_automagically_part_33 , which was used to synchronize a repo between git and subversion, with multiple developers using both git and subversion, and a proxy between them to do the synchronization.

Upvotes: 4

VonC
VonC

Reputation: 1324278

You might consider svn2git to easily import svn to git, and then its mirror ruby application git2svn.
More details in this question.
As mentioned in the other answers, 'git svn' is mandatory, but those ruby modules help you respect the "subversion branches/directory" while not having them as an actual directory in Git.

Upvotes: 6

Daniel Roseman
Daniel Roseman

Reputation: 599610

Surely an easier way to do it would be to have the main repository stay as Subversion, but use git-svn locally?

Upvotes: 1

Greg Hewgill
Greg Hewgill

Reputation: 993095

The best way to do this is to use git svn as a Subversion client. This provides two-way integration between a Subversion repository and a Git repository. Once you have a Git repository, you can push that anywhere else to publish it.

I do this regularly, at work there is a Subversion repository that is the "master" repository, and I usually use git svn to access it. Sometimes if I'm doing things that need more specific Subversion functionality like merging, I'll use the regular svn client against the repository instead.

Upvotes: 22

Related Questions