Mercurial Notes

This is an Email from my colleague Gareth:


Ian explained this a little last night.  Since this is going to come up a lot, I wanted to explain what the dialog options are.

You'll get this dialog if you've made changes to a repository at the same time as someone else.  (You committed changes to your local repository, then went to push them.  Someone else had sneaked in and pushed changes ahead of you that you don't have.)  You'll get this dialog.

If you imagine your repository, this is what it looked like after you committed your changes "L1" and "L2":

But some other developer (probably with a few extra cups of coffee in them because boy they did it awfully fast) made changes "R1" and "R2" at the same time and pushed them to the main repository ahead of you.  The dialog is saying you've got a situation like this:


There are three ways to handle it.  One is to force your changes anyway and split into two heads.  NEVER DO THIS.  It's not what we want.

The easiest thing to do is "Rebase", and it's always the first thing you should try. What "Rebase" does is looks at the files involved.  If you've both worked on completely different files, it will just update your repository to take the "R1" and "R2" changes, then stick your changes on top:

Now you can push your changes with no problem.   In the graph of the branch, this simply adds your changes as a new node after  that "coffee'd up" developer.  Since most of the time we'll all be working on different files, this is the most common scenario, and how we should try to handle it.

OK, but what if Mr/Mrs coffee worked on the SAME files as you did.  What a jerk!  Rebase doesn't work.  You get an error that a merge is required.  OK, no biggie.  Now you have to do a merge.  I'm not sure how the dialogs work and will update this when I find out, but you want to get to that second option "Merge two heads".

If you've changed different parts of the same file, the merge can be done automatically.  If not, you've got to handle the conflicts in the UI just like we did all the time in IDEA and CVS.  Once we're done and happy with the merge, we commit the updated files and push our changes.  The graph now looks like this, with "M1" being the combined streams of work.

Hope that helps.  Please let me know if there's problems with the explanation, or your experience differ with what I've described above.  Happy "Rebasing".

Thanks,

Gareth