Case 1: Updating the Working Directory
$ hg update [-r REV]
This switches the working directory to the specified revision. However if my working directory has modified changes, the changes are merged back with REV. I realize I can use the -C flag to discard my changes but I am trying to put across my concern to the behavior of update command in different scenarios.
Case 2: Switching to a Branch
$ hg update <bname>
This switches my working directory to <bname> branch. However my uncommitted changes are not merged until I explicitly use the merge command.
Case 3: Updating pulled change sets from a Remote Repository
$ hg pull
$ hg update
This again merges my working directory with the change sets from the remote repository after a recent pull.
Mercurial 1.9.1
It has to do with the relationships between changesets. If there is a direct path between the parent changeset of the working directory and the target changeset you’re updating to, Mercurial will try to transfer the changes in the working directory with a merge operation. So if the changeset you’re on is either a direct descendant or direct ancestor of the changeset you want to update to, it will usually work.
In the following diagrams, letters represent branch names and the numbers are the sequential revision numbers.
wdis the working directory.When Mercurial will merge uncommitted changes:
Update on the same branch:
Above, changes have been made based on A5. If you update to A4, Mercurial will merge the uncommitted changes to transfer them.
Also, if there are additional changesets (such as A6) this will still work, because A4
Update to different branch (this time, updating to B4):
Above, revisions 2 and 4 are on a different branch B, which has been recently merged back to branch A. Mercurial will also transfer uncommitted changes, because A5 and B4 are so closely related. And also:
Likewise, when you pull new changes from the remote repo, usually they will be descendants of the changeset that is the parent of your working directory, so that provides the direct relation that makes the merge of uncommitted changes possible:
When Mercurial will not merge uncommitted changes:
Update on the same branch:
Above, changes have been made based on A6. If you update to A5, Mercurial will refuse, saying either “outstanding uncommitted changes” or “crosses branches”. This is because you’re trying to merge uncommitted changes from one head to another head, and they are (by definition) not ancestors or descendants of each other. The same occurs with named branches, of course:
Getting around it
There’s a few different ways you can move your changes to a new parent when Mercurial won’t automatically try to merge the uncommitted changes: