gist JS

Tuesday, September 30, 2008

Merging with Git: conflicts!

Dramatis Personae:

git-svn rebase: our hero/ protagonist
(no-branch): a mysterious stranger
.dotest: an even more mysterious interloper

Scene I - The Setup

>>mate config/environment.rb
>>git add config/environment.rb
>>git-svn rebase

>>CONFLICT (content): Merge conflict in config/environment.rb

>>mate config/environment.rb (and fix problem...)
>>git add config/environment.rb

Scene 2 - Where it all goes wrong

Well, since we just added, maybe we should just commit.
>>git commit -m "merged conflict

At this point, everyone dies, commits are forever lost and you are left to rot in the bizarre (no branch) land that your $9 git tutorial, or not-yet-published book, never mentioned. Return to start.

Scene 2 --ammend

>> git rebase --continue !!!

Milk & Honey*
(or not. see the postscript)

Scene 3 - Where all is explained

The problem with scene 2 is that once a conflict occurs, git pops you into a new 'branch'-ish thing called (no branch). This is not a regular old branch afaict however. If you were to decide not to fix the conflict and just go on your merry way committing new code you'll be in for a lot of pain. You can tell if you're in this mysterious state by running 'git branch'. On git <>>[jdwyah@silvia sample]$ git rebase --continue
>>Applying: test
>>No changes - did you forget to use 'git add'?

Basically when you committed you essenitally stole your continue's thunder and it isn't happy about it.

Now you can do a --skip instead, and this is also written up here: Larry vs. the Git Rebase Merge Conflict but from what I've been able to reproduce I think he must've done the commit accidentally like I did and there's no reason not to do the continue instead. It's such a twitch reaction to add then commit I'm guessing that he did the same thing I did. That said, git rebase --skip does work as a way to get out of this mess.

Postscript (--ammend --ammend)

* Note, it might not necessarily be all milk & honey here. You may in fact, be left with... MORE CONFLICTS! Now why might this be? Well, the fact is that you may be rebasing onto your local branch which may have multiple commits. If this is the case, when git goes to replay your changes after the rebase merge it may well conflict multiple times: once for your first local commit, once for your second, etc...

It's quite possible to think that you're losing your mind at this point, since you can continue to get conflicts for the same darn file over and over again, but if you do keep merging things you should eventually make it out of the rabbit hole. Hodgies merge option is probably a good solution here, or alternatively you could merge your local commits into one big commit.


Matt Hodgson said...

The other option is to do a git rebase --abort

Yeah. Thats right. I don't rebase. You wanna fight about it? After my first few rebasing attempts with anything more than a few trivial changes I was in a constant and never ending string of conflict hell.

Rebasing sucks.

Better idea: Branch the branch you are trying to rebase from and do a merge on the branch you are trying to rebase. Then delete the duplicate rebasing branch. This works way better (and more predictably). Sure it probably confuses the hell out of git, but at least I get my code updated.


Jeff Dwyer said...

hodgie, you're a legend.

"Branch the branch you are trying to rebase from and do a merge on the branch you are trying to rebase."

I've read this sentence 6 times.



ahh. ok. I see you're doing this in an all new branch, but how is the result of your merge different from the result of my rebase? won't I get the same set of conflicts?

Matt Hodgson said...

That was the point I guess. Same result, but a more intuitive process. The way git handles rebasing is poor and I've received way too many errors that no amount of googling has been able to solve....

Anonymous said...


I apologize to comment here but was unable to locate the correct forum.

We've purchased your book and loved it and would like to try and use some of the examples from the book with the latest GWT available in main maven repository now.

Would you be so kind to update the examples to compilable with a stable 1.5.x (non RC) GWT version?

The current one doesn't compile because the shouldEnforceTypeVersioning method has been removed from AbstractSerializationStreamWriter class.


Jeff Dwyer said...

Hey anonymous,
You should be all set now. ToCollege.net now uses GWT 1.5.3.