Size: 2731
Comment:
|
Size: 3106
Comment: make it work on windows with copy paste too
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
== ["Tutorial"] - Merging changes == | == Tutorial - Merging changes == |
Line 3: | Line 3: |
In TutorialExport, we learned how to share a change with another person. But, since (as of version 0.6c anyway) ["Import"] isn't yet functional enough to handle merges correctly, we're going to demonstrate merging by pulling from another repository that has made an incompatible change. | In TutorialExport, we learned how to share a change with another person. But since (as of version 0.7) ["Import"] isn't functional enough to handle emailed merges correctly, we're going to demonstrate merging by pulling from another repository that has made an incompatible change. |
Line 5: | Line 5: |
First, we must create a reason to merge. Let's ["Clone"] the ''my-hello'' repository again: | First, we must create something to merge. Let's ["Clone"] the {{{my-hello}}} repository again: |
Line 8: | Line 8: |
$ cd .. $ hg clone my-hello my-hello-desc |
$ cd .. $ hg clone my-hello my-hello-desc |
Line 12: | Line 12: |
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 15: | Line 15: |
$ cd my-hello-desc $ vi hello.c |
$ cd my-hello-desc $ vi hello.c |
Line 25: | Line 25: |
To this: | to this: |
Line 31: | Line 31: |
Let's save and quit the editor, and ["Commit"] our change. This time, we save a few moments by using the ''-m'' option to the ''commit'' command, to save us from being dropped into another editor: | Let's save and quit the editor, and ["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 34: | Line 34: |
$ hg commit -m'Add description of hello.c' | $ hg commit -m "Add description of hello.c" |
Line 37: | Line 37: |
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"]. Will there be a problem when we want to 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 from one into the other? |
Line 39: | Line 39: |
This works just fine. While still in ''my-hello-desc'', let's ["Pull"] those 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 42: | Line 42: |
$ 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) |
$ 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) |
Line 52: | Line 52: |
This looks just like the output of ''pull'' from TutorialShareChange! So all we have to do is an ["Update"] now, right? | This looks just like the output of {{{pull}}} from TutorialShareChange! So all we have to do is an ["Update"] now, right? |
Line 55: | Line 55: |
$ 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) |
$ 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) |
Line 62: | Line 62: |
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. We simply follow the instructions: |
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: |
Line 67: | Line 65: |
$ hg update -m merging hello.c |
$ hg merge merging hello.c |
Line 71: | Line 69: |
And that's all there is to it; ["Mercurial"] was able to handle the merge completely automatically. If we look at ''hello.c'' now, we find that it contains /both/ the change from ''my-hello-new-output'' and the change from ''my-hello-desc''. | 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 MergeProgram). 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}}}. |
Line 73: | Line 71: |
Much of the time, when you are working with changes made by other people, this is the /only/ kind of merge you will need to perform. | (~-Note: before Mercurial version 0.9, `hg update -m` should have been used in place of `hg merge`-~). |
Line 75: | Line 73: |
Let us continue on, and learn how to deal with situations where conflicting changes have been made, in TutorialConflict. | When working with changes made by other people, this is the kind of merge you will end up performing most of the time. Let us continue on, however, and learn how to deal with situations where conflicting changes have been made in TutorialConflict. |
Tutorial - Merging changes
In TutorialExport, we learned how to share a change with another person. But since (as of version 0.7) ["Import"] isn't functional enough to handle emailed merges correctly, we're going to demonstrate merging by pulling from another repository that has made an incompatible change.
First, we must create something to merge. Let's ["Clone"] the my-hello repository again:
$ cd .. $ hg clone my-hello my-hello-desc
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"] 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 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 update' to get a working copy)
This looks just like the output of pull from TutorialShareChange! So all we have to do is an ["Update"] now, right?
$ 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)
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
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 MergeProgram). 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).
When working with changes made by other people, this is the kind of merge you will end up performing most of the time.
Let us continue on, however, and learn how to deal with situations where conflicting changes have been made in TutorialConflict.