Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git-Svn dcommit causes branch splitting

Tags:

git

svn

git-svn

I'm having a problem with git-svn dcommits making the git repository lose track of which commits are which.

I try to make sure that the master branch in git always follows trunk in the SVN repository. So whenever I'm working, I'm on a topic branch. Here's my scenario:

Working in a topic branch for a while

git checkout -b my-topic
git commit -m "blah blah blah"

Then I decide I'd like to merge my branch back in to master

git checkout master
git svn rebase #get any changes in svn
git rebase master my-topic
git merge my-topic --ff-only

Up until here, everything has gone well. I now have both master and my-topic up to speed and pointing at the same commit, and the entire history looks like this:

A -- B -- C - master + my-topic

However, when I do

git svn dcommit

I end up with a tree that looks like this (B and C are commits I originally made to the topic):

  -- B -- C - my-topic
 /
A -- B -- C - master + remotes/trunk

It seems like during the dcommit process, git pushes the commits up to SVN, then replays them back on top of master. The problem I think is that they get different committer information. I'm logging into svn with tortoise plink and an SSH key.

Commits in the git repository that have not been pushed to SVN have committer info as:

Collin Hockey <[email protected]>

Commits that have been pushed to the svn repository have this though:

chockey <chockey@6206317d-b652-48a9-a948-4036602fc523>

Is there any way I can keep these branches from splitting? I can sort of fix it by saying

git rebase master my-topic

again, but I feel like that should be unnecessary. The main problem with this is that once a branch's changes are pushed to SVN, git no longer thinks that branch has been merged anywhere. It makes it confusing to delete old branches you no longer need.

like image 837
Collin Avatar asked Apr 08 '11 13:04

Collin


1 Answers

The git svn dcommit command works as follows:

  1. Find the last commit coming from SVN; let's call it last-svn
  2. Send the commits in the range last-svn..HEAD to Subversion (discarding the e-mail by the way)
  3. Reset the HEAD to last-svn
  4. Update from SVN and create the corresponding commits

In other words, the commits you send to SVN are destroyed and recreated from the update from SVN. This must happen because the commits that come from SVN are different from the ones created with Git:

  • Their description contains a reference to the SVN revision
  • Their author e-mail is computed from the SVN username

That's why your branch my-topic diverges from master.

You can customize the way git svn dcommit computes the author e-mail from the SVN username with the --authors-file and --authors-prog options.

like image 71
Laurent Pireyn Avatar answered Sep 20 '22 02:09

Laurent Pireyn