Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easily duplicate bug fixes in an old svn repository into the new git repositories.

Tags:

git

svn

interop

We have moved most of our codebase from a monolithic svn repository into a set of git repositories. For various reasons, some work (on old versions of the project deployed in the field) has to continue in old svn branches, after they have been moved to git and deleted from the subversion trunk.

I have just done some work like this on an svn branch and re-applied the changes from the svn repository into the git repositories by doing the following:

cd <common_svn_commit_root>
svn diff -r 12344:12345 > ~/r12345.diff
gedit ~/r12345.diff
cd <common_git_commit_root>
git apply ~/r12345.diff

but it is rather cumbersome to do this for each and every svn commit, especially the gedit step, where I have to manually munge the svn paths into git paths (usually by prefixing the top level directory name).

One problem with trying some of the options presented so far is that the structure of the old svn repo and the new git repo are different. This is one of the reasons I have to edit the patch file.

The old directory structure was

svn
    configurations
        blah
        mine
        blam
    plugins
        foo
        core
        mine
        bar

Whereas the new structure is

svn
    plugins
        bar
git
    my_git
        my_config
        plugins
            mine
    core_git
        plugins
            core
    foo_git
        plugins
            foo

I would really like to know if there is an easier way to do this, and understand what the best practice is for this situation.

like image 325
Mark Booth Avatar asked Jul 04 '12 15:07

Mark Booth


People also ask

What does Git SVN clone do?

The git svn clone command transforms the trunk, branches, and tags in your SVN repository into a new Git repository. Depending on the structure of your SVN repo, the command needs to be configured differently.

How do I clone a SVN repository?

# Clone a repo with standard SVN directory layout (like git clone): git svn clone http://svn.example.com/project --stdlayout --prefix svn/ # Or, if the repo uses a non-standard directory layout: git svn clone http://svn.example.com/project -T tr -b branch -t tag --prefix svn/ # View all branches and tags you have ...

What is the difference between Git and SVN?

The difference between Git and SVN version control systems is that Git is a distributed version control system, whereas SVN is a centralized version control system. Git uses multiple repositories including a centralized repository and server, as well as some local repositories.


1 Answers

you can use git svn to synchronize your git repo with the changes from svn.

git svn --authors-file=authors.txt clone https://repo/svn/reponame/trunk reponame-git-svn

# if something aborts:
cd reponame-git-svn
git svn fetch

# create a new branch
git checkout -b dvcs

git remote add dvcs-svn https://repo/git/reponame.git

this will leave you with the svn sources in a git branch. To sync from svn to git:

git checkout master
# get the changes from svn
git svn rebase
git checkout dvcs

# apply the changes from svn
git rebase master

# fetch the changes from git repo to the local repo
git fetch dvcs-svn

# apply the changes from git repo to the branch dvcs
git rebase dvcs-svn/master

# push all changes back to git repo
git push dvcs-svn dvcs:master

we have better experience with rebase than with merge. Hopefully this does the job for you as well.

like image 159
wemu Avatar answered Nov 07 '22 16:11

wemu