9

I'm using git-svn to track multiple branches in the same svn repository. Usually this works fine, but today I've done some resets and rebases, and suddenly my branches wouldn't dcommit to the right remote branch anymore:

$ git branch
* master
  a
  b

$ git svn dcommit -n
Committing to svn://server/repo/trunk ...

$ git checkout a
$ git svn dcommit -n
Committing to svn://server/repo/branches/a ...

$ git checkout b
$ git svn dcommit -n
Committing to svn://server/repo/branches/a ...

So the branch b would commit to the branches/a directory instead of the branches/b directory.

I've tried changing the branch that is tracked:

$ git branch --set-upstream b remotes/b

And other things, but the only solution that worked was to delete the branch b and recreate it:

$ git branch -D b
$ git branch b remotes/b
$ git svn dcommit -n
Committing to svn://server/repo/branches/b ...

Now my question is: how does git svn determine what directory to commit to? And how do I modify this directory?

Thanks,
Jonas

1

3 Answers 3

5

The SVN configuration you are looking for is in the .git/config file of your cloned repository. It can be manipulated with a text editor. Here's a sample:

$ cat .git/config        
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
[svn-remote "svn"]
    url = https://pdfsam.svn.sourceforge.net/svnroot/pdfsam
    fetch = trunk:refs/remotes/trunk
    branches = branches/*:refs/remotes/*
    tags = tags/*:refs/remotes/tags/*

The branches are assumed to match name-to-name by default. To track a mismatched branch name, either rename the local branch or add an explicit configuration (remote) for the oddly-named branch:

[svn-remote "weirdbranch"]
    url = svn+ssh://ambientideas.com/svnrepos/myproject/branches/myweirdbranch
    fetch = :refs/remotes/git-svn-myweirdbranchlocalname

Additionally, if performing Git merges of branches from multiple SVN repos, the dcommit will (logically, but confusing to first time users) target the SVN URL of the first merge commit parent. The Git documentation states "git svn dcommit will attempt to commit on top of the SVN commit named in git log --grep=^git-svn-id: --first-parent -1"

If rebasing one SVN branch against another, this means that the "newest" commits (the subordinate branch) will be the target of the dcommit. Frequently, the user wants to target the dominant SVN repo (branch). This requires the user to use the --no-ff option when rebasing to ensure the last commit points to the dominant branch (new cherry-picked commits).

Other relevant StackOverflow questions include:

1
  • Thanks, that is valuable information indeed! I've also found that git will commit a branch X to remote branch R if it thinks X is based on R. So, by rebasing X on R, I could force git to commit onto the right remote branch. Feb 1, 2011 at 7:37
0

My problem with svn git was similar. My branch structure was hierarchical like this:

svn/projectX/branches/
svn/projectX/branches/Android
svn/projectX/branches/Android/dev-shared

I first followed instructions and examples in git-svn manual:

https://www.kernel.org/pub/software/scm/git/docs/git-svn.html

and cloned my trunk using:

git svn clone -s --prefix=svn/ https://mw.com/svn/projectX -T trunk -t tags -b branches/Android

I then checked out branches/Android/dev-shared branch made changes and commitedt them to my local git branch. I then tried "git svn dcommit -n" to see what it would do without actually committing.

I saw that it was trying to commit my branch commits to the trunk on svn.

SO glad I used the "-n" option and avoided committing to the wrong place.

After much research the best resource I found was:

http://www.janosgyerik.com/practical-tips-for-using-git-with-large-subversion-repositories/

The solution it suggested was to first checkout a new clone from svn using:

git svn clone http://me.com/projectX/trunk projectX

and then manually edit the .git\config file to add additional fetch entries for each of my branches I wanted to work on:

[svn-remote "svn"]
    url = https://me.com/svn/projectX
    fetch = trunk:refs/remotes/svn/trunk
    fetch = branches/Android/dev-shared:refs/remotes/svn/branches/Android/dev-shared

Then when I retried "git svn dcommit -n" it was now committing to the correct branch "branches/Android/dev-shared".

0

It determines which SVN branch is reachable from the commit you've got checked out (following only first parents), and commits to that branch. There can never be more than one since git-svn doesn't create branches on top of other branches.

You can modify it by rebasing your local branch before dcommitting so that it's a descendant of the SVN commit you want to commit on top of (i.e. the head of the SVN branch you want to commit to).

From https://git-scm.com/docs/git-svn:

git svn dcommit will attempt to commit on top of the SVN commit named in

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.