3

I have the following setup

svn repository

application
 |
 |-branches
 |  |
 |  |-develop-svn
 |
 |-trunk

local git repository

master
 |
 |-develop

master tracks remotes/trunk

develop tracks remotes/develop-svn

For some reason develop stopped tracking develop-svn.

When i checkout develop from master i get the following message.

$ (master) git checkout develop
Switched to branch develop
Your branch is ahead of 'develop-svn' by 59 commits.

When i try to commit to the svn repository, it tries to update the remote trunk.

$ (develop) git svn dcommit -n
Committing to https://servername/svn/application/trunk ...
...

It used to commit to https://servername/svn/application/branches/develop-svn

I already tried this command, which did not help:

$ (master) git branch --set-upstream develop develop-svn
Branch develop set up to track local refs/remotes/develop-svn.
$ (master) git checkout develop
Switched to branch develop
Your branch is ahead of 'develop-svn' by 59 commits.
$ (develop) git svn dcommit -n
Committing to https://servername/svn/application/trunk ...
...

My config looks like this

[svn-remote "svn"]
  url = https://servername/svn/application
  fetch = trunk:refs/remotes/trunk
  branches = branches/*:refs/remotes/*
  tags = tags/*:refs/remotes/tags/*
mrt181
  • 5,080
  • 8
  • 66
  • 86

1 Answers1

5

According to Pro Git, git svn dcommit decides which Subversion branch to push to based on the most recent svn-id in the history. The git svn documentation explains this is done by going back through the history following the first parent in each instance:

If you do merge, note the following rule: git svn dcommit will attempt to commit on top of the SVN commit named in

       git log --grep=^git-svn-id: --first-parent -1

You must therefore ensure that the most recent commit of the branch you want to dcommit to is the first parent of the merge. Chaos will ensue otherwise, especially if the first parent is an older commit on the same SVN branch.

(As I'm sure you'll have noticed, the svn-ids begin with a URL pointing to trunk or svn-develop, or whatever.)

So, if you try that command on the branch you're on, does it find the commit you expect? Or might you have rebased or merged in some way that might make the most recent git svn commit (in the sense above) one from the trunk in Subversion rather than the develop-svn branch?

Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • Hi, yes the above command returns an old commit that points to trunk. Is it possible to change this commit to another one and how to do this? – mrt181 Mar 22 '11 at 14:11
  • It's hard to say without understanding how this happened. If you look at the commit graph in a graphical tool like `gitk --all` can you see why that commit from `trunk` appears in the "first parent" history before one from `svn-develop`? – Mark Longair Mar 22 '11 at 14:33
  • Well a similar problem occured in another project. i had a faulty master so i merged master with develop, made some changes to master and commited these with dcommit. I then merged develop with master - all refs are at the same commit (HEAD, trunk, master, develop) except for develop-svn which is 3 commits behind. The git log --grep command gets a trunk commit as the last svn commit, even when i am on the develop branch. – mrt181 Mar 22 '11 at 16:37
  • 2
    It seems that git svn can't handle git merges. I have to use rebase. – mrt181 Mar 24 '11 at 10:30
  • @mrt181: Sorry, I forgot to reply to your earlier comment. `git svn` can handle merges in the sense that a merge will be represented by a single version that includes all the changes that were introduced by merging - you won't have the history of the branch you've just merged into your main branch represented in svn, as a result. Yes, using `git svn` inevitably involves a lot of rebasing. Unfortunately there wasn't enough information in your question or comment to suggest exactly which rebase command you'd want to fix the situation you're in. – Mark Longair Mar 24 '11 at 10:47
  • Can you tell me with which rebase command i am able to resolve the situation. I have to use the svn repository and i am facing this problem now frequently. – mrt181 Mar 25 '11 at 08:34
  • 2
    @mrt181: As I mentioned above, I can't really guess from the information here what command you need to run. The problem seems arise from you merging git branches back and forwards, and it really helps to avoid that if you want them to correspond to Subversion branches. One thing you could try is to find the last commit on the `svn-develop` branch - say that's called L - then checkout the `svn-develop` branch and do `git rebase -i L`, carefully removing from the list any commits that have an svn-id from trunk. As I say, that can only be a guess not knowing more about the commit graph. – Mark Longair Mar 26 '11 at 10:33
  • Thanks. I have merged master with develop but the graphs were not at the same commit. so i merged develop with master. both heads of each branch where at same graph node now, but my problem occured. i was able to fix it wiht you last suggestion. it seems impossible to merge svn branches the same way as in git. – mrt181 Mar 28 '11 at 12:09