There is any way to synchronize GIT and Subversion repositories?

后端 未结 7 517
花落未央
花落未央 2020-12-23 10:17

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,

相关标签:
7条回答
  • 2020-12-23 10:33

    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...

    0 讨论(0)
  • 2020-12-23 10:35

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

    0 讨论(0)
  • 2020-12-23 10:36

    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.

    0 讨论(0)
  • 2020-12-23 10:41

    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.

    0 讨论(0)
  • 2020-12-23 10:46

    There's a new solution that performs exactly what you want --- SubGit. It is concurrent-safe (I can't say the same about git-svn-based bash scripts).

    0 讨论(0)
  • 2020-12-23 10:46

    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.

    0 讨论(0)
提交回复
热议问题