Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git-svn: reset tracking for master

I'm using git-svn to work with an SVN repository. My working copies have been created using git svn clone -s http://foo.bar/myproject so that my working copy follows the default directory scheme for SVN (trunk, tags, branches).

Recently I've been working on a branch which was created using git-svn branch myremotebranch and checked-out using git checkout --track -b mybranch myremotebranch. I needed to work from multiple locations, so from the branch I git-svn dcommit-ed files to the SVN repository quite regularly.

After finishing my changes, I switched back to the master and executed a merge, committed the merge, and tried to dcommit the successful merge to the remote trunk.

It seems as though after the merge the remote tracking for the master has switched to the branch I was working on:

# git checkout master # git merge mybranch ... (successful) # git add . # git commit -m '...' # git svn dcommit Committing to http://foo.bar/myproject/branches/myremotebranch ... # 

Is there a way I can update the master so that it's following remotes/trunk as before the merge?

I'm using git 1.7.0.5, if that's any help.

It would be useful if you could also explain why this happened, so I can avoid the problem happening again. Thanks!

Edit:

Here is my current .git/config:

[core]     repositoryformatversion = 0     filemode = true     bare = false     logallrefupdates = true     autocrlf = false [svn-remote "svn"]     url = http://foo.bar/myproject     fetch = trunk:refs/remotes/trunk     branches = branches/*:refs/remotes/*     tags = tags/*:refs/remotes/tags/* [branch "mybranch"]     remote = .     merge = refs/remotes/myremotebranch 

So it seems that the trunk is pointing to the correct place. However, switching to the branch then back to the master doesn't help; git svn dcommit in the master still tries to push to myremotebranch.

like image 469
Phillip B Oldham Avatar asked May 14 '10 16:05

Phillip B Oldham


People also ask

Can I use git and SVN at the same time?

No interaction between them. Just ignore the . git folder for SVN and the . svn folder for Git and you should be fine.

How do I clone a SVN repository?

# Clone a repo with standard SVN directory layout (like git clone): git svn clone http://svn.example.com/project --stdlayout --prefix svn/ # Or, if the repo uses a non-standard directory layout: git svn clone http://svn.example.com/project -T tr -b branch -t tag --prefix svn/ # View all branches and tags you have ...

What does git SVN fetch do?

This retrieves all the changes from the SVN repository and applies them on top of your local commits in your current branch. This works like, you know, a rebase between two branches :) You can also use git svn fetch to retrieve the changes from the SVN repository but without applying them to your local branch.

Which is Better git or SVN?

SVN is better than Git for architecture performance, binary files, and usability. And it may be better for access control and auditability, based on your needs.


1 Answers

When there are no changes on trunk, git does a fast-forward merge and simply sets the local "master" branch to the commit on your branch. Git-svn doesn't know how to commit fast-forward merges back to trunk, in fact it thinks "master" now is pointing to the svn branch.

To work around this, use git merge --no-ff when merging. This will force git to create a merge commit, which can then be dcommitted to svn.

like image 137
Daniel Avatar answered Oct 07 '22 16:10

Daniel