Differences between revisions 9 and 13 (spanning 4 versions)
Revision 9 as of 2005-09-03 20:36:03
Size: 2635
Comment:
Revision 13 as of 2006-05-15 16:21:00
Size: 3374
Comment: updates for v0.9: update -m -> merge, undo -> rollback
Deletions are marked like this. Additions are marked like this.
Line 5: Line 5:
["Mercurial"] handles more complex ["Merge"] cases, too. It is not all that uncommon for two people to edit the exact same lines of a file, and then have to figure out what to do. We call these cases conflicts; figuring out what to do about a conflict is called resolving it. ["Mercurial"] handles more complex ["Merge"] cases, too. It is not all that uncommon for two people to edit the exact same lines of a file, and then have to figure out what to do. These cases are called conflicts; figuring out what to do about a conflict is called resolving it.
Line 7: Line 7:
We need to create an artificial conflict situation. Let's start by making a ["Clone"] of {{{my-hello}}}: Let's first create an artificial conflict situation. As we did previously, let's start by making a ["Clone"] of {{{my-hello}}}:
Line 13: Line 13:
Line 17: Line 18:
$ vi hello.c
Line 18: Line 20:
We'll change {{{main}}} to read like this:
We change {{{main}}} to read like this:

{{{#!cplusplus numbers=off
int main(int argc, char **argv)
{
        printf("hello, world!\n");
        printf("sure am glad I'm not using CVS!\n");
        return 0;
}
}}}

And we ["Commit"] the change:
Line 21: Line 35:
int main(int argc, char **argv)
{
    printf("hello, world!\n");
    printf("sure am glad I'm not using CVS!\n");
    return 0;
}
$ hg commit -m 'Give thanks for dodging bullet'
Line 28: Line 37:
And ["Commit"] the change:
Line 30: Line 38:
{{{
$ hg commit -m'Give thanks for dodging bullet'
}}}
Line 36: Line 41:
$ hg pull ../my-hello-new-output/
pulling from ../my-hello-new-output/
$ hg pull ../my-hello-new-output
pulling from ../my-hello-new-output
Line 41: Line 46:
adding file revisions
added 1 changesets with 1 changes to 1 files
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
Line 45: Line 50:
Line 52: Line 58:
(use update -m to merge across branches or -C to lose changes) (use 'hg merge' to merge across branches or 'hg update -C' to lose changes)
Line 54: Line 60:
As in TutorialMerge, we have to run {{{update -m}}}. But here's where things change. ["Mercurial"] cannot now automatically ["Merge"], because the same line of the same source file has been modified in a different way by each ChangeSet (the one we just ["Commit"]ted, and the one we just ["Pull"]ed).
As in TutorialMerge, we have to run {{{hg merge}}}. As before,
the MergeProgram will be started under cover
. It will usually not be able to ["Merge"] automatically, because the same line of the same source file has been modified in a different way by each ChangeSet (the one we just ["Commit"]ted, and the one we just ["Pull"]ed). 
Line 57: Line 65:
$ hg update -m $ hg merge
Line 59: Line 67:
At this point, what happens may be a matter of luck. If we are lucky, and have a MergeProgram installed, we will be dropped into the MergeProgram. Here, we will be able to see what conflicts there are between the two changes, and decide how to resolve them.
Line 61: Line 68:
If we are not lucky, and do not have a MergeProgram installed, we will be dropped into our text editor, which will be visiting the file we need to ["Merge"]. Doing this by hand is ''highly'' error-prone and tedious. It is best to exit the editor and use the {{{hg undo}}} command to reverse the effect of the ["Pull"], then install a MergeProgram and try again. At this point, what happens depends on what programs are installed on our computer. If we are provident or lucky, and have a graphical MergeProgram installed, we will be able to see what conflicts there are between the two changes, and decide how to resolve them.
Line 63: Line 70:
Now let us continue on to TutorialConclusion. ["Mercurial"] is using a per-file 3-way merge. This means that there are 3 input files for merging process, and those are:
 * Local file (from current repository)
 * Other file (from repository being merged)
 * Base file (last version of file before branches separated)

For more information about 3-way, see [http://revctrl.org/ThreeWayMerge ThreeWayMerge] on the [http://revctrl.org/ Revctrl wiki].

Else, if we do not have a graphical MergeProgram installed, we will be dropped into a text editor, which will be visiting the file we need to ["Merge"]. Doing this by hand is '''highly''' error-prone and tedious. It is best to exit the editor and use the {{{hg rollback}}} command to reverse the effect of the ["Pull"], then install a MergeProgram, and then try again.

(~-Note: before Mercurial version 0.9, `hg update -m` should have been used in place of `hg merge` and `hg undo` should have been used instead of `hg rollback`-~).


Now let's continue and finish on to TutorialConclusion.

Tutorial - merging conflicting changes

We learned how to deal with simple ["Merge"]s in TutorialMerge.

["Mercurial"] handles more complex ["Merge"] cases, too. It is not all that uncommon for two people to edit the exact same lines of a file, and then have to figure out what to do. These cases are called conflicts; figuring out what to do about a conflict is called resolving it.

Let's first create an artificial conflict situation. As we did previously, let's start by making a ["Clone"] of my-hello:

$ cd ..
$ hg clone my-hello my-hello-not-cvs

Now let's add a new line of output to hello.c:

$ cd my-hello-not-cvs
$ vi hello.c

We change main to read like this:

int main(int argc, char **argv)
{
        printf("hello, world!\n");
        printf("sure am glad I'm not using CVS!\n");
        return 0;
}

And we ["Commit"] the change:

$ hg commit -m 'Give thanks for dodging bullet'

Recall that in TutorialFirstChange, we created a ChangeSet in my-hello-new-output that also added a second line of output. What happens when we try to ["Pull"] that change in here?

$ hg pull ../my-hello-new-output
pulling from ../my-hello-new-output
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
(run 'hg update' to get a working copy)

So far, so good. Let's try an ["Update"].

$ hg update
this update spans a branch affecting the following files:
 hello.c (resolve)
aborting update spanning branches!
(use 'hg merge' to merge across branches or 'hg update -C' to lose changes)

As in TutorialMerge, we have to run hg merge. As before, the MergeProgram will be started under cover. It will usually not be able to ["Merge"] automatically, because the same line of the same source file has been modified in a different way by each ChangeSet (the one we just ["Commit"]ted, and the one we just ["Pull"]ed).

$ hg merge

At this point, what happens depends on what programs are installed on our computer. If we are provident or lucky, and have a graphical MergeProgram installed, we will be able to see what conflicts there are between the two changes, and decide how to resolve them.

["Mercurial"] is using a per-file 3-way merge. This means that there are 3 input files for merging process, and those are:

  • Local file (from current repository)
  • Other file (from repository being merged)
  • Base file (last version of file before branches separated)

For more information about 3-way, see [http://revctrl.org/ThreeWayMerge ThreeWayMerge] on the [http://revctrl.org/ Revctrl wiki].

Else, if we do not have a graphical MergeProgram installed, we will be dropped into a text editor, which will be visiting the file we need to ["Merge"]. Doing this by hand is highly error-prone and tedious. It is best to exit the editor and use the hg rollback command to reverse the effect of the ["Pull"], then install a MergeProgram, and then try again.

(Note: before Mercurial version 0.9, hg update -m should have been used in place of hg merge and hg undo should have been used instead of hg rollback).

Now let's continue and finish on to TutorialConclusion.

TutorialConflict (last edited 2019-03-28 10:43:14 by IanMoody)