Differences between revisions 27 and 28
Revision 27 as of 2008-02-10 12:42:51
Size: 4429
Editor: abuehl
Comment: moving link to Branch up
Revision 28 as of 2008-05-05 16:05:13
Size: 3861
Editor: abuehl
Comment: update for Mercurial 1.0
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
In TutorialExport, we learned how to share a change with another person. But since (as of version 0.7) [:Import:import] isn't functional enough to handle emailed merges correctly, we're going to demonstrate merging by pulling from another [:Repository:repository] that has made an incompatible change. In [:TutorialExport], we learned how to share a change with another person. In this tutorial here, we're going to demonstrate [:Merge:merging] by [:Pull:pulling] from another [:Repository:repository] that has made a diverging change (see also [:Branch]).
Line 5: Line 5:
First, we must create something to [:Merge:merge]. Let's [:Clone:clone] the {{{my-hello}}} repository again: First, we must create something to merge. Let's [:Clone:clone] the `my-hello` repository again:
Line 10: Line 10:
updating working directory
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
Line 12: Line 14:
We are going to give {{{hello.c}}} a description in its comment section. We are going to give `hello.c` a description in its comment section.
Line 31: Line 33:
Let's save and quit the editor, and [:Commit:commit] our change. This time, we save some time by using the {{{-m}}} option to the {{{commit}}} command, to spare us from being dropped into an editor: Let's save and quit the editor, and [:Commit:commit] our change. This time, we save some time by using the `-m` option to the `commit` command, to spare us from being dropped into an editor:
Line 37: Line 39:
At this point, we have made one change to {{{hello.c}}} in the {{{my-hello-new-output}}} repository, and another change to {{{hello.c}}} in the {{{my-hello-desc}}} repository (see [:Branch]). How do we ''merge'' these two diverging lines of development? Will there be a problem when we want to [:Pull:pull] from one into the other? At this point, we have made one change to `hello.c` in the `my-hello-new-output` repository, and another change to `hello.c` in the `my-hello-desc` repository. How do we ''merge'' these two diverging lines of development? Will there be a problem when we want to [:Pull:pull] from one into the other?
Line 39: Line 41:
This works just fine. While still in {{{my-hello-desc}}}, let's pull the changes from {{{my-hello-new-output}}} and see what happens: This works just fine. While still in `my-hello-desc`, let's pull the changes from `my-hello-new-output` and see what happens:
Line 52: Line 54:
This looks just like the output of {{{pull}}} from TutorialShareChange! So all we have to do is an [:Update:update] now, right? This looks just like the output of `pull` from TutorialShareChange! So all we have to do is an [:Update:update] now, right?
Line 56: Line 58:
abort: update spans branches, use 'hg merge' or 'hg update -C' to lose changes abort: crosses branches (use 'hg merge' or 'hg update -C')
Line 68: Line 70:
(~-''Note for Windows users:'' Mercurial is missing a merge program, if you get an error like ''`hgmerge is not recognized as an internal or external command.`'' See MergeProgram for information on how to fix this.-~)

That's all there is to it! Mercurial was able to handle the merge automatically for you, by calling under the covers the {{{hgmerge}}} script (or whatever is your merge program. Depending on your environment, the `hgmerge` may call a graphical merge resolver tool. If we look at {{{hello.c}}}, we find that it contains ''both'' the change from {{{my-hello-new-output}}} and the change from {{{my-hello-desc}}}.

(~-Note: before Mercurial version 0.9, `hg update -m` should have been used in place of `hg merge`-~).
That's all there is to it! Mercurial was able to handle the merge automatically for you. If we look at `hello.c`, we find that it contains ''both'' the change from `my-hello-new-output` and the change from `my-hello-desc`.
Line 75: Line 73:
change to the repository, as suggested on the last line of the output from {{{hg merge}}}: change to the repository, as suggested on the last line of the output from `hg merge`:
Line 83: Line 81:
To show the changes of our merging, we use the {{{annotate}}} command to show [:ChangeSet:changeset] information per file line.
Note that revision 2 is our modification to {{{my-hello-desc}}} repository and revision 3 is the changes pulled and merged from
from {{{my-hello-new-output}}} repository to {{{my-hello-desc}}} repository.
To show the changes of our merging, we use the `annotate` command to show [:ChangeSet:changeset] information per file line.
Note that revision 2 is our modification to `my-hello-desc` repository and revision 3 is the changes pulled and merged from
from `my-hello-new-output` repository to `my-hello-desc` repository.
Line 108: Line 106:
Let us continue on, however, and learn how to deal with situations where [:Conflict:conflicting] changes have been made in TutorialConflict. Let us continue on, however, and learn how to deal with situations where [:Conflict:conflicting] changes have been made in [:TutorialConflict].

Tutorial - Merging changes

In [:TutorialExport], we learned how to share a change with another person. In this tutorial here, we're going to demonstrate [:Merge:merging] by [:Pull:pulling] from another [:Repository:repository] that has made a diverging change (see also [:Branch]).

First, we must create something to merge. Let's [:Clone:clone] the my-hello repository again:

$ cd ..
$ hg clone my-hello my-hello-desc
updating working directory
2 files updated, 0 files merged, 0 files removed, 0 files unresolved

We are going to give hello.c a description in its comment section.

$ cd my-hello-desc
$ vi hello.c

Let's change the second line from this:

 * hello.c

to this:

 * hello.c - hello, world

Let's save and quit the editor, and [:Commit:commit] our change. This time, we save some time by using the -m option to the commit command, to spare us from being dropped into an editor:

$ hg commit -m "Add description of hello.c"

At this point, we have made one change to hello.c in the my-hello-new-output repository, and another change to hello.c in the my-hello-desc repository. How do we merge these two diverging lines of development? Will there be a problem when we want to [:Pull:pull] from one into the other?

This works just fine. While still in my-hello-desc, let's pull the changes from my-hello-new-output and see what happens:

$ 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 heads' to see heads, 'hg merge' to merge)

This looks just like the output of pull from TutorialShareChange! So all we have to do is an [:Update:update] now, right?

$ hg update
abort: crosses branches (use 'hg merge' or 'hg update -C')

Nope. Something has happened. Mercurial is telling us that we must merge the changes that we made in each repository. This sounds painful, right? It's actually very easy. Let's follow the instructions of the last line of output:

$ hg merge
merging hello.c
0 files updated, 1 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)

That's all there is to it! Mercurial was able to handle the merge automatically for you. If we look at hello.c, we find that it contains both the change from my-hello-new-output and the change from my-hello-desc.

When working with changes made by other people, this is the kind of merge you will end up performing most of the time. Don't forget to commit this change to the repository, as suggested on the last line of the output from hg merge:

$ hg commit -m "Merged changes from my-hello-new-output"

There shouldn't be any output from this command.

To show the changes of our merging, we use the annotate command to show [:ChangeSet:changeset] information per file line. Note that revision 2 is our modification to my-hello-desc repository and revision 3 is the changes pulled and merged from from my-hello-new-output repository to my-hello-desc repository.

$ hg annotate hello.c
0: /*
2:  * hello.c - hello, world
0:  *
0:  * Placed in the public domain by Bryan O'Sullivan
0:  *
0:  * This program is not covered by patents in the United States or other
0:  * countries.
0:  */
0:
0: #include <stdio.h>
0:
0: int main(int argc, char **argv)
0: {
0:      printf("hello, world!\n");
3:      printf("sure am glad I'm using Mercurial!\n");
0:      return 0;
0: }

Let us continue on, however, and learn how to deal with situations where [:Conflict:conflicting] changes have been made in [:TutorialConflict].


CategoryTutorial

TutorialMerge (last edited 2012-11-06 16:18:47 by abuehl)