Blogged by Ujihisa. Standard methods of programming and thoughts including Clojure, Vim, LLVM, Haskell, Ruby and Mathematics written by a Japanese programmer. github/ujihisa

Wednesday, October 13, 2010

Git-SVN Low-Risk Practice


  • You are supposed to work on a svn branch topic.
  • You hate svn.
  • You want to follow changes of svn trunk.
  • You hate the merging in svn.
  • You already checked out the svn repository with git-svn-clone with stdlayout option.

Wrong way

First you make a local git branch topic that'll sync with svn branch topic.

$ git checkout -b topic topic

Then you work on the branch, including git-commit a lot. Before you go home you push the changes into the main svn repository by git-svn-dcommit.

You sometimes have to see the changes in trunk.

$ git checkout master
$ git svn rebase

And merges the changes into your topic branch.

$ git checkout topic
$ git merge --no-ff master

You know that merge without --no-ff option breaks git-svn system so you did --no-ff.

Finally you finished all your work on the topic branch and tried to merge the changes into trunk.

$ git checkout master
$ git merge --no-ff topic

That causes a lot of conflicts that you have to resolve manually.

Right way

The "Wrong way" example had two failures.

  • ambiguous name of topic
  • merge from trunk to topic

The first one is not fatal but annoying. Every time you run a git command with specifying a branch name shows a warning message that your local git branch name is ambiguous. You should have make a local git branch in which name is different to the svn branch.

$ git checkout -b tpc topic

Next. You are not supposed to merge changes in trunk to topic branch that will be merged to trunk. That causes a lot of conflicts.

The solution is that you create another local git branch that doesn't sync svn branch directly.

$ git checkout -b t tpc

Instead of trying to merge from master to t, try to rebase from master to t. Regard the tpc branch for very temporary one.

$ git checkout master
$ git svn rebase
$ git checkout t
$ git rebase master

$ git checkout tpc
$ git svn dcommit
$ svn delete `git svn info --url`
$ git checkout t
$ git branch -d -r topic
$ git branch -D tpc
$ git svn branch topic
$ git checkout -b tpc topic

figure 1

Note that this approach make the svn repository log messy. Be resigned; that's the subversion.

No comments:

Post a Comment