comparison en/ch02-tour-merge.xml @ 826:a17d6390a480

More fixes to chapters 1 and 2.
author Bryan O'Sullivan <bos@serpentine.com>
date Sun, 03 May 2009 20:27:09 -0700
parents 29f0f79cf614
children d2aacc06e562
comparison
equal deleted inserted replaced
825:d7d09cda83d2 826:a17d6390a480
11 11
12 <sect1> 12 <sect1>
13 <title>Merging streams of work</title> 13 <title>Merging streams of work</title>
14 14
15 <para id="x_339">Merging is a fundamental part of working with a distributed 15 <para id="x_339">Merging is a fundamental part of working with a distributed
16 revision control tool.</para> 16 revision control tool. Here are a few cases in which the need
17 to merge work arises.</para>
17 <itemizedlist> 18 <itemizedlist>
18 <listitem><para id="x_33a">Alice and Bob each have a personal copy of a 19 <listitem>
20 <para id="x_33a">Alice and Bob each have a personal copy of a
19 repository for a project they're collaborating on. Alice 21 repository for a project they're collaborating on. Alice
20 fixes a bug in her repository; Bob adds a new feature in 22 fixes a bug in her repository; Bob adds a new feature in
21 his. They want the shared repository to contain both the 23 his. They want the shared repository to contain both the
22 bug fix and the new feature.</para> 24 bug fix and the new feature.</para>
23 </listitem> 25 </listitem>
24 <listitem><para id="x_33b">I frequently work on several different tasks for 26 <listitem>
25 a single project at once, each safely isolated in its own 27 <para id="x_33b">Cynthia frequently works on several different
26 repository. Working this way means that I often need to 28 tasks for a single project at once, each safely isolated in
27 merge one piece of my own work with another.</para> 29 its own repository. Working this way means that she often
28 </listitem></itemizedlist> 30 needs to merge one piece of her own work with
29 31 another.</para>
30 <para id="x_33c">Because merging is such a common thing to need to do, 32 </listitem>
31 Mercurial makes it easy. Let's walk through the process. We'll 33 </itemizedlist>
32 begin by cloning yet another repository (see how often they 34
33 spring up?) and making a change in it.</para> 35 <para id="x_33c">Because we need to merge often, Mercurial makes
36 the process easy. Let's walk through a merge. We'll begin by
37 cloning yet another repository (see how often they spring up?)
38 and making a change in it.</para>
34 39
35 &interaction.tour.merge.clone; 40 &interaction.tour.merge.clone;
36 41
37 <para id="x_33d">We should now have two copies of 42 <para id="x_33d">We should now have two copies of
38 <filename>hello.c</filename> with different contents. The 43 <filename>hello.c</filename> with different contents. The
39 histories of the two repositories have also diverged, as 44 histories of the two repositories have also diverged, as
40 illustrated in <xref 45 illustrated in <xref
41 linkend="fig:tour-merge:sep-repos"/>.</para> 46 linkend="fig:tour-merge:sep-repos"/>. Here is a copy of our
42 47 file from one repository.</para>
43 &interaction.tour.merge.cat; 48
49 &interaction.tour.merge.cat1;
50
51 <para>And here is our slightly different version from the other
52 repository.</para>
53
54 &interaction.tour.merge.cat2;
44 55
45 <figure id="fig:tour-merge:sep-repos"> 56 <figure id="fig:tour-merge:sep-repos">
46 <title>Divergent recent histories of the <filename 57 <title>Divergent recent histories of the <filename
47 class="directory">my-hello</filename> and <filename 58 class="directory">my-hello</filename> and <filename
48 class="directory">my-new-hello</filename> 59 class="directory">my-new-hello</filename>
63 command says something about <quote>heads</quote>.</para> 74 command says something about <quote>heads</quote>.</para>
64 75
65 <sect2> 76 <sect2>
66 <title>Head changesets</title> 77 <title>Head changesets</title>
67 78
68 <para id="x_341">A head is a change that has no descendants, or children, 79 <para id="x_341">Remember that Mercurial records what the parent
69 as they're also known. The tip revision is thus a head, 80 of each change is. If a change has a parent, we call it a
70 because the newest revision in a repository doesn't have any 81 child or descendant of the parent. A head is a change that
71 children, but a repository can contain more than one 82 has no children. The tip revision is thus a head, because the
83 newest revision in a repository doesn't have any children.
84 There are times when a repository can contain more than one
72 head.</para> 85 head.</para>
73 86
74 <figure id="fig:tour-merge:pull"> 87 <figure id="fig:tour-merge:pull">
75 <title>Repository contents after pulling from <filename 88 <title>Repository contents after pulling from <filename
76 class="directory">my-hello</filename> into <filename 89 class="directory">my-hello</filename> into <filename
97 not safe to use revision numbers when discussing changesets.) 110 not safe to use revision numbers when discussing changesets.)
98 We can view the heads in a repository using the <command 111 We can view the heads in a repository using the <command
99 role="hg-cmd">hg heads</command> command.</para> 112 role="hg-cmd">hg heads</command> command.</para>
100 113
101 &interaction.tour.merge.heads; 114 &interaction.tour.merge.heads;
102
103 </sect2> 115 </sect2>
116
104 <sect2> 117 <sect2>
105 <title>Performing the merge</title> 118 <title>Performing the merge</title>
106 119
107 <para id="x_344">What happens if we try to use the normal <command 120 <para id="x_344">What happens if we try to use the normal <command
108 role="hg-cmd">hg update</command> command to update to the 121 role="hg-cmd">hg update</command> command to update to the
109 new tip?</para> 122 new tip?</para>
110 123
111 &interaction.tour.merge.update; 124 &interaction.tour.merge.update;
112 125
113 <para id="x_345">Mercurial is telling us that the <command role="hg-cmd">hg 126 <para id="x_345">Mercurial is telling us that the <command
114 update</command> command won't do a merge; it won't update 127 role="hg-cmd">hg update</command> command won't do a merge;
115 the working directory when it thinks we might want to do 128 it won't update the working directory when it thinks we might
116 a merge, unless we force it to do so. Instead, we use the 129 want to do a merge, unless we force it to do so.
117 <command role="hg-cmd">hg merge</command> command to merge the 130 (Incidentally, forcing the update with <command>hg update
118 two heads.</para> 131 -C</command> would revert any uncommitted changes in the
132 working directory.)</para>
133
134 <para>To start a merge between the two heads, we use the
135 <command role="hg-cmd">hg merge</command> command.</para>
119 136
120 &interaction.tour.merge.merge; 137 &interaction.tour.merge.merge;
121 138
122 <para id="x_347">This updates the working directory so that it contains 139 <para id="x_347">We resolve the contents of <filename>hello.c</filename>
123 changes from <emphasis>both</emphasis> heads, which is 140
124 reflected in both the output of <command role="hg-cmd">hg 141 This updates the working directory so that it
142 contains changes from <emphasis>both</emphasis> heads, which
143 is reflected in both the output of <command role="hg-cmd">hg
125 parents</command> and the contents of 144 parents</command> and the contents of
126 <filename>hello.c</filename>.</para> 145 <filename>hello.c</filename>.</para>
127 146
128 &interaction.tour.merge.parents; 147 &interaction.tour.merge.parents;
129
130 </sect2> 148 </sect2>
131 <sect2> 149 <sect2>
132 <title>Committing the results of the merge</title> 150 <title>Committing the results of the merge</title>
133 151
134 <para id="x_348">Whenever we've done a merge, <command role="hg-cmd">hg 152 <para id="x_348">Whenever we've done a merge, <command role="hg-cmd">hg
206 system. It first tries a few fully automatic merging tools; if 224 system. It first tries a few fully automatic merging tools; if
207 these don't succeed (because the resolution process requires 225 these don't succeed (because the resolution process requires
208 human guidance) or aren't present, it tries a few 226 human guidance) or aren't present, it tries a few
209 different graphical merging tools.</para> 227 different graphical merging tools.</para>
210 228
211 <para id="x_34f">It's also possible to get Mercurial to run another program 229 <para id="x_34f">It's also possible to get Mercurial to run a
212 or script instead of <command>hgmerge</command>, by setting the 230 specific program or script, by setting the
213 <envar>HGMERGE</envar> environment variable to the name of your 231 <envar>HGMERGE</envar> environment variable to the name of your
214 preferred program.</para> 232 preferred program.</para>
215 233
216 <sect2> 234 <sect2>
217 <title>Using a graphical merge tool</title> 235 <title>Using a graphical merge tool</title>
308 <para id="x_35d">In this example, I'll set 326 <para id="x_35d">In this example, I'll set
309 <envar>HGMERGE</envar> to tell Mercurial to use the 327 <envar>HGMERGE</envar> to tell Mercurial to use the
310 non-interactive <command>merge</command> command. This is 328 non-interactive <command>merge</command> command. This is
311 bundled with many Unix-like systems. (If you're following this 329 bundled with many Unix-like systems. (If you're following this
312 example on your computer, don't bother setting 330 example on your computer, don't bother setting
313 <envar>HGMERGE</envar>.)</para> 331 <envar>HGMERGE</envar>. You'll get dropped into a GUI file
332 merge tool instead, which is much preferable.)</para>
314 333
315 &interaction.tour-merge-conflict.merge; 334 &interaction.tour-merge-conflict.merge;
316 335
317 <para id="x_35f">Because <command>merge</command> can't resolve the 336 <para id="x_35f">Because <command>merge</command> can't resolve the
318 conflicting changes, it leaves <emphasis>merge 337 conflicting changes, it leaves <emphasis>merge
331 prevent us from <quote>fixing up</quote> the affected files 350 prevent us from <quote>fixing up</quote> the affected files
332 ourselves, and committing the results of our merge:</para> 351 ourselves, and committing the results of our merge:</para>
333 352
334 &interaction.tour-merge-conflict.commit; 353 &interaction.tour-merge-conflict.commit;
335 354
355 <note>
356 <title>Where is the <command>hg resolve</command> command?</title>
357
358 <para>The <command>hg resolve</command> command was introduced
359 in Mercurial 1.1, which was released in December 2008. If
360 you are using an older version of Mercurial (run <command>hg
361 version</command> to see), this command will not be
362 present. If your version of Mercurial is older than 1.1,
363 you should strongly consider upgrading to a newer version
364 before trying to tackle complicated merges.</para>
365 </note>
336 </sect2> 366 </sect2>
337 </sect1> 367 </sect1>
338 <sect1 id="sec:tour-merge:fetch"> 368 <sect1 id="sec:tour-merge:fetch">
339 <title>Simplifying the pull-merge-commit sequence</title> 369 <title>Simplifying the pull-merge-commit sequence</title>
340 370
356 <para id="x_365">Mercurial provides a flexible extension mechanism that lets 386 <para id="x_365">Mercurial provides a flexible extension mechanism that lets
357 people extend its functionality, while keeping the core of 387 people extend its functionality, while keeping the core of
358 Mercurial small and easy to deal with. Some extensions add new 388 Mercurial small and easy to deal with. Some extensions add new
359 commands that you can use from the command line, while others 389 commands that you can use from the command line, while others
360 work <quote>behind the scenes,</quote> for example adding 390 work <quote>behind the scenes,</quote> for example adding
361 capabilities to the server.</para> 391 capabilities to Mercurial's built-in server mode.</para>
362 392
363 <para id="x_366">The <literal role="hg-ext">fetch</literal> 393 <para id="x_366">The <literal role="hg-ext">fetch</literal>
364 extension adds a new command called, not surprisingly, <command 394 extension adds a new command called, not surprisingly, <command
365 role="hg-cmd">hg fetch</command>. This extension acts as a 395 role="hg-cmd">hg fetch</command>. This extension acts as a
366 combination of <command role="hg-cmd">hg pull -u</command>, 396 combination of <command role="hg-cmd">hg pull -u</command>,
367 <command role="hg-cmd">hg merge</command> and <command 397 <command role="hg-cmd">hg merge</command> and <command
368 role="hg-cmd">hg commit</command>. It begins by pulling 398 role="hg-cmd">hg commit</command>. It begins by pulling
369 changes from another repository into the current repository. If 399 changes from another repository into the current repository. If
370 it finds that the changes added a new head to the repository, it 400 it finds that the changes added a new head to the repository, it
371 begins a merge, then (if the merge succeeded) commits the result 401 updates to the new head, begins a merge, then (if the merge
372 of the merge with an automatically-generated commit message. If 402 succeeded) commits the result of the merge with an
373 no new heads were added, it updates the working directory to the 403 automatically-generated commit message. If no new heads were
374 new tip changeset.</para> 404 added, it updates the working directory to the new tip
405 changeset.</para>
375 406
376 <para id="x_367">Enabling the <literal 407 <para id="x_367">Enabling the <literal
377 role="hg-ext">fetch</literal> extension is easy. Edit the 408 role="hg-ext">fetch</literal> extension is easy. Edit the
378 <filename role="special">.hgrc</filename> file in your home 409 <filename role="special">.hgrc</filename> file in your home
379 directory, and either go to the <literal 410 directory, and either go to the <literal