7

I'm using git-svn to work against svn repository. The layout is standard, and I have created the local repository with:

$ git svn clone -s http://mysvnrepo
(master)$ 

I need to work on a remote (svn) branch - MyBranch, so I created a local branch to track the remote one:

(master)$ git checkout -b localMyBranch remotes/MyBranch
(localMyBranch)$

I keep working and committing to the local branch as I go, and occasionally I do dcommit:

(localMyBranch)$ git svn dcommit

Meanwhile other people are working on the trunk, and from time to time I want to merge back the changes from trunk to my branch to keep them in sync. That's where I get really confused, as I could not find a good information how to perform this. So far I know that I need to do:

(localMyBranch)$ git svn dcommit
(localMyBranch)$ git checkout master
(master)$ git svn rebase

Now what? I read that this is NOT the right way to go:

(master)$ git checkout localMyBranch
(localMyBranch)$ git rebase master

As it's going to mess the merge info for svn.

So what is the best way to "rebase" my remote svn branch to the remote trunk, preserving the merge info for svn?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sunny Milenov
  • 21,990
  • 6
  • 80
  • 106

1 Answers1

7

You'll want to create a local working branch to handle your merge. The key is that you need a branch that is not actively tracking a remote svn branch.

Try this:

(localMyBranch)$ git checkout -b merge_work
(merge_work)$ git merge master
(merge_work)$ git checkout localMyBranch
(localMyBranch)$ git rebase merge_work

and vice-versa for merges the other way.

EDIT

If you are using git-svn 1.7.7 or higher, there is a configuration setting to tell git-svn to populate the mergeinfo property on the remote repository:

git config --global svn.pushmergeinfo true
Peter Bratton
  • 6,302
  • 6
  • 39
  • 61
  • Thanks. Is it going to preserve the merge info from svn POV? – Sunny Milenov Feb 08 '12 at 13:44
  • Yes, if you configure git to do so. I will edit the answer to include the command to do so. – Peter Bratton Feb 08 '12 at 15:11
  • @jordan002: Does it really work? I'm used to do like [this](http://stackoverflow.com/a/4908930/158074) answer recommends, but this way seems to be simpler. Also, the first line should probably be `git checkout -b merge_work`, right? – rsenna Aug 09 '12 at 17:43