Chapter 3. A Tour of Mercurial: Merging Work
We’ve now covered cloning a repository, making changes in a repository, and pulling or pushing changes from one repository into another. Our next step is merging changes from separate repositories.
Merging Streams of Work
Merging is a fundamental part of working with a distributed revision control tool. Here are a few cases in which the need to merge work arises:
Alice and Bob each have a personal copy of a repository for a project they’re collaborating on. Alice fixes a bug in her repository; Bob adds a new feature in his. They want the shared repository to contain both the bug fix and the new feature.
Cynthia frequently works on several different tasks for a single project at once, each safely isolated in its own repository. Working this way means that she often needs to merge one piece of her own work with another.
Because we need to merge often, Mercurial makes the process easy. Let’s walk through a merge. We’ll begin by cloning yet another repository (see how often they spring up?) and making a change in it:
$
cd ..
$
hg clone hello my-new-hello
updating working directory 2 files updated, 0 files merged, 0 files removed, 0 files unresolved$
cd my-new-hello
# Make some simple edits to hello.c.$
my-text-editor hello.c
$
hg commit -m 'A new hello for a new day.'
We should now have two copies of hello.c with different contents. The histories of the two repositories have also diverged, as illustrated in Figure 3-1. Here is a copy of our file ...
Get Mercurial: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.