0

When I setup my branch I did:

git svn rebase
git checkout -b branch-a

Then I pushed that branch to the remote git repository and a colleague and I did work on it using git commit, git pull and git push.

Now, I wanted to pull in all the new changes from subversion so I did:

git checkout master
git svn rebase
git checkout branch-a
git rebase master

At this point I'm confused. What appeared to happen was that git would get to a commit with 1 or more conflicts and force me to resolve them. However, what the conflicts appeared to be was git having HEAD point to the tip of the tree (with the very latest code) and then attempting to apply every change one by one on top as if it were applying them to the original branch point.

It felt like I was re-writing all the code again and most of the resolution was to keep the HEAD chunk and get rid of the commit chunk.

My expectation was that the git rebase master command would start at the commit before the branch, add every commit from master and then add every commit on the branch. This would then yield a tip on the branch almost identical to what it was before the rebase.

So, can anybody explain what I'm failing to understand. Failing that, can anybody suggest how to find out why git is deciding to do that. What would I be looking for in a git log to see why it was doing that.

Edit: 2012-03-06 Further research has shown that we seem to have multiple copies of a couple of commits in our branch and a branch structure, from git log --graph which shows multiple branches when we thought there was only one.

A snippet (identifying details removed and commit messages have been replaced with message-n. Message-n refers to identical messages):

| * | commit f5c48df66ed9d733364562d8f125866aa6483c1e
| | | Author: commiter-b
| | | Date:   Mon Feb 27 16:18:05 2012 -0800
| | | 
| | |     Message-4
| | |    
| * | commit e6115229e629c237b08d0b2e149353f33ff66bd1
| | | Author: commiter-a
| | | Date:   Mon Feb 27 15:49:02 2012 -0800
| | | 
| | |     Message-3
| | |    
| * | commit f85981736c59231dc34a7cef4fceab5cffdbdff2
| |/  Author: committer-a
| |   Date:   Mon Feb 27 14:20:56 2012 -0800
| |   
| |       Message-2
| |   
| * commit b09ba82e6290f5905d4c98fdcfbe2220d221e762
|   Author: committer-a
|   Date:   Mon Feb 27 14:04:13 2012 -0800
|   
|       Message-1
|  
* commit 4d2892c239acfab5c9845518fde98ba551f273e6
| Author: committer-a
| Date:   Mon Mar 5 09:13:19 2012 -0800
| 
|     UN-3710 Fixes after merge from svn

---8<----- snip

* commit 8307d1ae8214ebe3eac5bdc5b835c21f89d727bd
| Author: committer-b
| Date:   Mon Feb 27 16:18:05 2012 -0800
| 
|     Message-4
|  
* commit 859acc56de59877cb721914443c63ad97882cb41
| Author: committer-a
| Date:   Mon Feb 27 15:49:02 2012 -0800
| 
|     Message-3
|  
* commit 93e15921d735333194970cefc673a8b953e80838
| Author: committer-a
| Date:   Mon Feb 27 14:20:56 2012 -0800
| 
|     Message-2
|  
* commit 7a863bb44be5c5019a0e0958460324dc3cfb2e6b
  Author: committer-a
  Date:   Mon Feb 27 14:04:13 2012 -0800

      Message-1

Our git workflow is conservative, I believe. We use git-svn to maintain master which is pushed to a remote git repository. We branch master and two or more committers work on it using git pull origin branch-a and git push origin.

Now that we've noticed this feature of the problem we will be carefully watching in future for what event proximately causes it.

2
  • I'm confused. I think you're describing exactly what a git rebase is supposed to do. Did you expect to have no conflicts? Had some of the changes you made already been committed to Subversion?
    – mpontillo
    Mar 3, 2012 at 1:46
  • But, my understanding is that git rebase works from the base of the branch. Instead it seemed to apply every commit to the tip. No, our changes hadn't been committed to subversion. A lot of these conflicts were on files that were new on that branch - thus could not conflict against svn. (I'm confused too - I don't know where to look to figure out what git is thinking).
    – Sarge
    Mar 3, 2012 at 2:32

1 Answer 1

5

First off, a quick summary of what git rebase does.

If you have history that looks like this:

trunk  branch
  |   /
  B  C
  | /
  |/
  A
  |
  |

And you git rebase trunk when you're on branch, here's what you get:

trunk/branch
   |
   C
   |
   B
   |
   A
   |
   |

That's why it's called a rebase - the previous base of branch was commit A - that's the point at which it diverged from its "upstream" branch, trunk. After the operation, the new base is B, the newer HEAD of trunk. You have re-based it.

git svn rebase just does this automatically, transplanting the changes you've made onto the new commits coming in from SVN.

Now, there is one gotcha. git-svn, for hysterical raisins, doesn't use git notes to store its metadata. Instead, it rewrites the commit objects themselves, adding git-svn-id lines to the end of each commit message. This causes the SHA1 identifiers of each commit to change. So, even identical commits are different - and may conflict with alternate-universe versions of themselves!

This is likely what you're seeing when you attempt to git rebase master from branch-a: branch-a diverged from some non-committed-to-SVN version of a previous state of master, so now when you attempt to merge, you'll get conflicts between the things changed on both sides.

This is a limitation of git-svn: once you push a change to SVN, you must be careful to only use the pushed-to-SVN rewritten version of the commit. You can't mix the pre-committed and post-committed forms, because they're "different" changes with the same contents.

You may verify this is what you're attempting to do by examining the changes from git merge-base master branch-a to master and branch-a. You'll likely see the same change on both sides.

To get yourself out of the rut in this particular case, delete your branch, create a fresh one from master, then git cherry-pick the changes from branch-a in order, omitting the ones which master already contains. In the future, be more careful about using the not-yet-in-SVN revisions...

5
  • This is a really great answer but, sadly, didn't actually help with our problem. We didn't push any changes from the feature branch to SVN so there was no opportunity for git-svn to rewrite the SHA1 identifiers. However, the comment about git merge-base was very useful.
    – Sarge
    Mar 6, 2012 at 16:35
  • @Sarge I'm curious: was history rewritten somehow? Was the output of git merge-base different from the point at which you thought the branch had diverged?
    – Borealid
    Mar 6, 2012 at 19:32
  • Yes - the commit messages on a few early commits were changed.
    – Sarge
    Mar 6, 2012 at 20:43
  • Oh, and the merge base of branch-a and master is correct - just all the history on branch-a has multiple branches and multiple commits.
    – Sarge
    Mar 6, 2012 at 20:53
  • @Sarge You've probably figured this out by now, but the branches only share history from the point of the first rewrite. So you're going to get many conflicts if "a few early commits" were changed and they were before the point of diversion.
    – Borealid
    Mar 7, 2012 at 2:41

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.