Size: 2672
Comment:
|
Size: 2697
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
== ["Tutorial"] - merging conflicting changes == | == Tutorial - merging conflicting changes == |
Line 7: | Line 7: |
We need to create an artificial conflict situation. Let's start by making a ["Clone"] of ''my-hello'': | We need to create an artificial conflict situation. Let's start by making a ["Clone"] of {{{my-hello}}}: |
Line 11: | Line 11: |
$ hg clone my-hello my-hello-not-cvs | $ hg clone my-hello my-hello-not-cvs |
Line 13: | Line 14: |
Now let's add a new line of output to ''hello.c'': |
Now let's add a new line of output to {{{hello.c}}}: |
Line 18: | Line 18: |
Line 19: | Line 20: |
We'll change ''main'' to read like this: |
We'll change {{{main}}} to read like this: |
Line 24: | Line 24: |
{ printf("hello, world!\n"); printf("sure am glad I'm not using CVS!\n"); return 0; } |
{ printf("hello, world!\n"); printf("sure am glad I'm not using CVS!\n"); return 0; } |
Line 30: | Line 31: |
Line 35: | Line 35: |
Line 36: | Line 37: |
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? |
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? |
Line 41: | Line 41: |
pulling from ../my-hello-new-output/ searching for changes adding changesets adding manifests adding file revisions modified 1 files, added 1 changesets and 1 new revisions (run 'hg update' to get a working copy) |
pulling from ../my-hello-new-output/ searching for changes adding changesets adding manifests adding file revisions modified 1 files, added 1 changesets and 1 new revisions (run 'hg update' to get a working copy) |
Line 49: | Line 50: |
Line 54: | Line 54: |
this update spans a branch affecting the following files: hello.c (resolve) aborting update spanning branches! (use update -m to perform a branch merge) |
this update spans a branch affecting the following files: hello.c (resolve) aborting update spanning branches! (use update -m to perform a branch merge) |
Line 59: | 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 {{{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). |
Line 64: | Line 64: |
Line 65: | Line 66: |
Line 68: | 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. | 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. |
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. We call these cases conflicts; figuring out what to do about a conflict is called resolving it.
We need to create an artificial conflict situation. 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
We'll 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 ["Commit"] the change:
$ hg commit -t'Give thanks for dodging bullet'
Recall that in TutorialFirstChange, we created a ChangeSet in my-hello-new-output thatalso 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 revisions modified 1 files, added 1 changesets and 1 new revisions (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 update -m to perform a branch merge)
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).
~/hg/my-hello-tmp $ hg update -m
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.
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 ishighly 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.
Now let us continue on to TutorialConclusion.