Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial update will overwrite my changes instead of merging

Tags:

mercurial

I am coming from CVS background.

Currently, I have 2 mercurial repositories developed parallel. hello-world-bugfix and hello-world-feature (This one is being cloned from hello-world-bugfix)

Now, I want to merge the bug fixed code from hello-world-bugfix into hello-world-feature, so that end of the day, I will get a merged file.

[BUG2 BUG2 BUG2]

START
[BUG1 BUG1 BUG1]

[FEATURE2 FEATURE2 FEATURE2]

Here is how all the things looks like before, pulling and merging. The below two files had already been committed.

alt text


alt text


Now, I perform pull from hello-world-feature, to pull changes from hello-world-bugfix. alt text

Then, I perform update, with always merge options turned on. alt text

Here is my merged file???

[BUG2 BUG2 BUG2]

START
[BUG1 BUG1 BUG1]

It seems that my previous committed [FEATURE2 FEATURE2 FEATURE2] being overwritten.

It seems that I shouldn't perform update step, which will not merge feature with bug, but overwrite feature away with bug. What is the next correct step I should do after pulling? (through TortoiseHg), so that I can get bug fix code, and remain feature code there?

Here is the final repository view of hello-world-feature alt text

like image 658
Cheok Yan Cheng Avatar asked Dec 09 '10 07:12

Cheok Yan Cheng


1 Answers

The "always merge" option doesn't do what you think it does.

It only merges uncommitted changes.

When you update, committed files are replaced with the new version.

To merge committed changes, ie. merge branches, you need to do an explicit merge.

So, I would select the BUG2 BUG2 BUG2 changeset in the log, then right-click on the FEATURE2 FEATURE2 FEATURE2 changeset and click Merge, and follow the instructions.

Let me expand on what the "Always merge" checkbox does.

Let's say I have two changesets in my repository, I update to the first of them, then I start modifying one of the files.

At some point I decide it would be better to have started from the other changeset instead, so I want to update to it, keeping my modifications.

If I simply do an update, with uncommitted changes, I get this dialog box when I try to update:

Confirm Update

However, if I check the "Always merge (when possible)" checkbox, it will simply assume that I clicked on the Merge button in that dialog and not prompt me.

So the "Always merge" does not have any function at all on committed files, it won't introduce merges for you, it will only try to move your local changes along with the update.

like image 133
Lasse V. Karlsen Avatar answered Oct 06 '22 01:10

Lasse V. Karlsen