Differences between revisions 4 and 5
Revision 4 as of 2005-08-26 01:22:26
Size: 2743
Editor: waste
Comment:
Revision 5 as of 2005-08-26 01:31:26
Size: 2771
Editor: waste
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
== [Tutorial] - Merging changes == == Tutorial - Merging changes ==
Line 9: Line 9:
 $ hg clone my-hello my-hello-desc   $ hg clone my-hello my-hello-desc
Line 15: Line 16:
 $ vi hello.c   $ vi hello.c
Line 21: Line 23:
Line 26: Line 29:
Line 31: Line 35:
Line 38: Line 43:
 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 50: Line 56:
 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 61: Line 68:
 merging hello.c   merging hello.c

Tutorial - Merging changes

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.

First, we must create a reason 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 a few moments by using the -m option to the commit command, to save us from being dropped into another 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"]. 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"] those 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 revisions
  modified 1 files, added 1 changesets and 1 new revisions
  (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 update -m to perform a branch merge)

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:

 $ hg update -m
  merging hello.c

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 containsboth the change from my-hello-new-output and the change from my-hello-desc.

Much of the time, when you are working with changes made by other people, this is theonly kind of merge you will need to perform.

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

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