gitsvndcommit

git svn dcommit on local branch re-creates local master


Background:

Our team needs to connect to an svn server and work on a particular branch (not the svn trunk). On top, we need to also get the trunk and merge between them.

I have set up a local git repository connected to our branch ("svn+ssh...project/branches/X").

Then, I have manually added the trunk as a new svn connection ("svn+ssh...project/trunk") (I added a new remote target for the svn trunk, to .git/config) and renamed my branches as follows:

master (connected to project/branches/X) was renamed to master-X

the branch connected to project/trunk was renamed to master-trunk.

Question:

When I git svn dcommit on the master-X local branch, a new 'master' branch is created, with the same effect as if I did:

git svn dcommit
git co master-X -b master

Can I prevent the master branch from being recreated?

(every time it is created I delete it manually afterwards).

Edit:

My .git/config now looks like this:

# original/default configuration settings skipped for brevity

[svn-remote "svn"]
    url = svn+ssh://...project/branches/X
    fetch = :refs/remotes/git-svn

[svn-remote "svn-trunk"]
    url = svn+ssh://...project/trunk
    fetch = :refs/remotes/git-svn-trunk

The last three lines were added by me.


Solution

  • This is old Git behaviour, that has been fixed in recent Git releases. Anything more recent than Git 1.7.12 will no longer automatically recreate a master branch. You can run git --version to get the version of Git you're currently running.

    That's not much use if the version that comes with your operating system is earlier than 1.7.12 (the latest I have easy access to, between my Debian, RHEL and Cygwin systems, is 1.7.9).

    If you want to, you should be able to make the change yourself, however. Find the copy of git-svn or git-svn.perl on your system (on mine, it's /usr/lib/git-core/git-svn), then make the following changes:

    The above changes will apply the patch that changed this behaviour in the Git source code. You can see that for yourself: the relevant commit is v1.7.11.2-250-ge3bd4dd by Marcin Owsiany.