comparison en/ch02-tour-merge.xml @ 718:4e23c220d1b0

Update chapter 2
author Bryan O'Sullivan <bos@serpentine.com>
date Mon, 06 Apr 2009 22:05:44 -0700
parents 0b45854f0b7b
children e9ef075327c1
comparison
equal deleted inserted replaced
717:2b193ab0df9a 718:4e23c220d1b0
110 110
111 &interaction.tour.merge.update; 111 &interaction.tour.merge.update;
112 112
113 <para id="x_345">Mercurial is telling us that the <command role="hg-cmd">hg 113 <para id="x_345">Mercurial is telling us that the <command role="hg-cmd">hg
114 update</command> command won't do a merge; it won't update 114 update</command> command won't do a merge; it won't update
115 the working directory when it thinks we might be wanting to do 115 the working directory when it thinks we might want to do
116 a merge, unless we force it to do so. Instead, we use the 116 a merge, unless we force it to do so. Instead, we use the
117 <command role="hg-cmd">hg merge</command> command to merge the 117 <command role="hg-cmd">hg merge</command> command to merge the
118 two heads.</para> 118 two heads.</para>
119 119
120 &interaction.tour.merge.merge; 120 &interaction.tour.merge.merge;
121
122 <para id="x_347">This updates the working directory so that it contains
123 changes from <emphasis>both</emphasis> heads, which is
124 reflected in both the output of <command role="hg-cmd">hg
125 parents</command> and the contents of
126 <filename>hello.c</filename>.</para>
127
128 &interaction.tour.merge.parents;
129
130 </sect2>
131 <sect2>
132 <title>Committing the results of the merge</title>
133
134 <para id="x_348">Whenever we've done a merge, <command role="hg-cmd">hg
135 parents</command> will display two parents until we <command
136 role="hg-cmd">hg commit</command> the results of the
137 merge.</para>
138
139 &interaction.tour.merge.commit;
140
141 <para id="x_349">We now have a new tip revision; notice that it has
142 <emphasis>both</emphasis> of our former heads as its parents.
143 These are the same revisions that were previously displayed by
144 <command role="hg-cmd">hg parents</command>.</para>
145
146 &interaction.tour.merge.tip;
147
148 <para id="x_34a">In <xref
149 linkend="fig:tour-merge:merge"/>, you can see a
150 representation of what happens to the working directory during
151 the merge, and how this affects the repository when the commit
152 happens. During the merge, the working directory has two
153 parent changesets, and these become the parents of the new
154 changeset.</para>
121 155
122 <figure id="fig:tour-merge:merge"> 156 <figure id="fig:tour-merge:merge">
123 <title>Working directory and repository during merge, and 157 <title>Working directory and repository during merge, and
124 following commit</title> 158 following commit</title>
125 <mediaobject> 159 <mediaobject>
128 </imageobject> 162 </imageobject>
129 <textobject><phrase>XXX add text</phrase></textobject> 163 <textobject><phrase>XXX add text</phrase></textobject>
130 </mediaobject> 164 </mediaobject>
131 </figure> 165 </figure>
132 166
133 <para id="x_347">This updates the working directory so that it contains 167 <para>We sometimes talk about a merge having
134 changes from <emphasis>both</emphasis> heads, which is 168 <emphasis>sides</emphasis>: the left side is the first parent
135 reflected in both the output of <command role="hg-cmd">hg 169 in the output of <command rold="hg-cmd">hg parents</command>,
136 parents</command> and the contents of 170 and the right side is the second. If the working directory
137 <filename>hello.c</filename>.</para> 171 was at e.g. revision 5 before we began a merge, that revision
138 172 will become the left side of the merge.</para>
139 &interaction.tour.merge.parents;
140
141 </sect2>
142 <sect2>
143 <title>Committing the results of the merge</title>
144
145 <para id="x_348">Whenever we've done a merge, <command role="hg-cmd">hg
146 parents</command> will display two parents until we <command
147 role="hg-cmd">hg commit</command> the results of the
148 merge.</para>
149
150 &interaction.tour.merge.commit;
151
152 <para id="x_349">We now have a new tip revision; notice that it has
153 <emphasis>both</emphasis> of our former heads as its parents.
154 These are the same revisions that were previously displayed by
155 <command role="hg-cmd">hg parents</command>.</para>
156
157 &interaction.tour.merge.tip;
158
159 <para id="x_34a">In <xref
160 linkend="fig:tour-merge:merge"/>, you can see a
161 representation of what happens to the working directory during
162 the merge, and how this affects the repository when the commit
163 happens. During the merge, the working directory has two
164 parent changesets, and these become the parents of the new
165 changeset.</para>
166
167 </sect2> 173 </sect2>
168 </sect1> 174 </sect1>
175
169 <sect1> 176 <sect1>
170 <title>Merging conflicting changes</title> 177 <title>Merging conflicting changes</title>
171 178
172 <para id="x_34b">Most merges are simple affairs, but sometimes you'll find 179 <para id="x_34b">Most merges are simple affairs, but sometimes you'll find
173 yourself merging changes where each modifies the same portions 180 yourself merging changes where each side modifies the same portions
174 of the same files. Unless both modifications are identical, 181 of the same files. Unless both modifications are identical,
175 this results in a <emphasis>conflict</emphasis>, where you have 182 this results in a <emphasis>conflict</emphasis>, where you have
176 to decide how to reconcile the different changes into something 183 to decide how to reconcile the different changes into something
177 coherent.</para> 184 coherent.</para>
178 185
190 changes; while someone else made different changes to the same 197 changes; while someone else made different changes to the same
191 text. Our task in resolving the conflicting changes is to 198 text. Our task in resolving the conflicting changes is to
192 decide what the file should look like.</para> 199 decide what the file should look like.</para>
193 200
194 <para id="x_34e">Mercurial doesn't have a built-in facility for handling 201 <para id="x_34e">Mercurial doesn't have a built-in facility for handling
195 conflicts. Instead, it runs an external program called 202 conflicts. Instead, it runs an external program, usually one
196 <command>hgmerge</command>. This is a shell script that is 203 that displays some kind of graphical conflict resolution
197 bundled with Mercurial; you can change it to behave however you 204 interface. By default, Mercurial tries to find one of several
198 please. What it does by default is try to find one of several
199 different merging tools that are likely to be installed on your 205 different merging tools that are likely to be installed on your
200 system. It first tries a few fully automatic merging tools; if 206 system. It first tries a few fully automatic merging tools; if
201 these don't succeed (because the resolution process requires 207 these don't succeed (because the resolution process requires
202 human guidance) or aren't present, the script tries a few 208 human guidance) or aren't present, it tries a few
203 different graphical merging tools.</para> 209 different graphical merging tools.</para>
204 210
205 <para id="x_34f">It's also possible to get Mercurial to run another program 211 <para id="x_34f">It's also possible to get Mercurial to run another program
206 or script instead of <command>hgmerge</command>, by setting the 212 or script instead of <command>hgmerge</command>, by setting the
207 <envar>HGMERGE</envar> environment variable to the name of your 213 <envar>HGMERGE</envar> environment variable to the name of your
297 different versions of the file, we'll set up an environment 303 different versions of the file, we'll set up an environment
298 suitable for running our merge.</para> 304 suitable for running our merge.</para>
299 305
300 &interaction.tour-merge-conflict.pull; 306 &interaction.tour-merge-conflict.pull;
301 307
302 <para id="x_35d">In this example, I won't use Mercurial's normal 308 <para id="x_35d">In this example, I'll set
303 <command>hgmerge</command> program to do the merge, because it
304 would drop my nice automated example-running tool into a
305 graphical user interface. Instead, I'll set
306 <envar>HGMERGE</envar> to tell Mercurial to use the 309 <envar>HGMERGE</envar> to tell Mercurial to use the
307 non-interactive <command>merge</command> command. This is 310 non-interactive <command>merge</command> command. This is
308 bundled with many Unix-like systems. If you're following this 311 bundled with many Unix-like systems. (If you're following this
309 example on your computer, don't bother setting 312 example on your computer, don't bother setting
310 <envar>HGMERGE</envar>.</para> 313 <envar>HGMERGE</envar>.)</para>
311
312 <para id="x_35e"><emphasis role="bold">XXX FIX THIS
313 EXAMPLE.</emphasis></para>
314 314
315 &interaction.tour-merge-conflict.merge; 315 &interaction.tour-merge-conflict.merge;
316 316
317 <para id="x_35f">Because <command>merge</command> can't resolve the 317 <para id="x_35f">Because <command>merge</command> can't resolve the
318 conflicting changes, it leaves <emphasis>merge 318 conflicting changes, it leaves <emphasis>merge
339 <title>Simplifying the pull-merge-commit sequence</title> 339 <title>Simplifying the pull-merge-commit sequence</title>
340 340
341 <para id="x_362">The process of merging changes as outlined above is 341 <para id="x_362">The process of merging changes as outlined above is
342 straightforward, but requires running three commands in 342 straightforward, but requires running three commands in
343 sequence.</para> 343 sequence.</para>
344 <programlisting>hg pull 344 <programlisting>hg pull -u
345 hg merge 345 hg merge
346 hg commit -m 'Merged remote changes'</programlisting> 346 hg commit -m 'Merged remote changes'</programlisting>
347 <para id="x_363">In the case of the final commit, you also need to enter a 347 <para id="x_363">In the case of the final commit, you also need to enter a
348 commit message, which is almost always going to be a piece of 348 commit message, which is almost always going to be a piece of
349 uninteresting <quote>boilerplate</quote> text.</para> 349 uninteresting <quote>boilerplate</quote> text.</para>
358 Mercurial small and easy to deal with. Some extensions add new 358 Mercurial small and easy to deal with. Some extensions add new
359 commands that you can use from the command line, while others 359 commands that you can use from the command line, while others
360 work <quote>behind the scenes,</quote> for example adding 360 work <quote>behind the scenes,</quote> for example adding
361 capabilities to the server.</para> 361 capabilities to the server.</para>
362 362
363 <para id="x_366">The <literal role="hg-ext">fetch</literal> extension adds a 363 <para id="x_366">The <literal role="hg-ext">fetch</literal>
364 new command called, not surprisingly, <command role="hg-cmd">hg 364 extension adds a new command called, not surprisingly, <command
365 fetch</command>. This extension acts as a combination of 365 role="hg-cmd">hg fetch</command>. This extension acts as a
366 <command role="hg-cmd">hg pull</command>, <command 366 combination of <command role="hg-cmd">hg pull -u</command>,
367 role="hg-cmd">hg update</command> and <command 367 <command role="hg-cmd">hg merge</command> and <command
368 role="hg-cmd">hg merge</command>. It begins by pulling 368 role="hg-cmd">hg commit</command>. It begins by pulling
369 changes from another repository into the current repository. If 369 changes from another repository into the current repository. If
370 it finds that the changes added a new head to the repository, it 370 it finds that the changes added a new head to the repository, it
371 begins a merge, then commits the result of the merge with an 371 begins a merge, then (if the merge succeeded) commits the result
372 automatically-generated commit message. If no new heads were 372 of the merge with an automatically-generated commit message. If
373 added, it updates the working directory to the new tip 373 no new heads were added, it updates the working directory to the
374 changeset.</para> 374 new tip changeset.</para>
375 375
376 <para id="x_367">Enabling the <literal role="hg-ext">fetch</literal> 376 <para id="x_367">Enabling the <literal
377 extension is easy. Edit your <filename 377 role="hg-ext">fetch</literal> extension is easy. Edit the
378 role="special">.hgrc</filename>, and either go to the <literal 378 <filename role="special">.hgrc</filename> file in your home
379 directory, and either go to the <literal
379 role="rc-extensions">extensions</literal> section or create an 380 role="rc-extensions">extensions</literal> section or create an
380 <literal role="rc-extensions">extensions</literal> section. Then 381 <literal role="rc-extensions">extensions</literal> section. Then
381 add a line that simply reads <quote><literal>fetch 382 add a line that simply reads
382 </literal></quote>.</para> 383 <quote><literal>fetch=</literal></quote>.</para>
384
383 <programlisting>[extensions] 385 <programlisting>[extensions]
384 fetch =</programlisting> 386 fetch =</programlisting>
385 <para id="x_368">(Normally, on the right-hand side of the 387
386 <quote><literal>=</literal></quote> would appear the location of 388 <para id="x_368">(Normally, the right-hand side of the
389 <quote><literal>=</literal></quote> would indicate where to find
387 the extension, but since the <literal 390 the extension, but since the <literal
388 role="hg-ext">fetch</literal> extension is in the standard 391 role="hg-ext">fetch</literal> extension is in the standard
389 distribution, Mercurial knows where to search for it.)</para> 392 distribution, Mercurial knows where to search for it.)</para>
390 393
391 </sect1> 394 </sect1>