comparison en/ch04-daily.xml @ 773:3b640272a966

Progres on resolve
author Bryan O'Sullivan <bos@serpentine.com>
date Sun, 12 Apr 2009 00:05:30 -0700
parents b338f5490029
children 29f0f79cf614
comparison
equal deleted inserted replaced
772:dbe5f4bb6507 773:3b640272a966
24 &interaction.daily.files.add; 24 &interaction.daily.files.add;
25 25
26 <para id="x_1a5">After you run a <command role="hg-cmd">hg commit</command>, 26 <para id="x_1a5">After you run a <command role="hg-cmd">hg commit</command>,
27 the files that you added before the commit will no longer be 27 the files that you added before the commit will no longer be
28 listed in the output of <command role="hg-cmd">hg 28 listed in the output of <command role="hg-cmd">hg
29 status</command>. The reason for this is that <command 29 status</command>. The reason for this is that by default, <command
30 role="hg-cmd">hg status</command> only tells you about 30 role="hg-cmd">hg status</command> only tells you about
31 <quote>interesting</quote> files&emdash;those that you have 31 <quote>interesting</quote> files&emdash;those that you have (for
32 modified or told Mercurial to do something with&emdash;by 32 example) modified, removed, or renamed. If you have a repository
33 default. If you have a repository that contains thousands of 33 that contains thousands of files, you will rarely want to know
34 files, you will rarely want to know about files that Mercurial 34 about files that Mercurial is tracking, but that have not
35 is tracking, but that have not changed. (You can still get this 35 changed. (You can still get this information; we'll return to
36 information; we'll return to this later.)</para> 36 this later.)</para>
37 37
38 <para id="x_1a6">Once you add a file, Mercurial doesn't do anything with it 38 <para id="x_1a6">Once you add a file, Mercurial doesn't do anything with it
39 immediately. Instead, it will take a snapshot of the file's 39 immediately. Instead, it will take a snapshot of the file's
40 state the next time you perform a commit. It will then continue 40 state the next time you perform a commit. It will then continue
41 to track the changes you make to the file every time you commit, 41 to track the changes you make to the file every time you commit,
49 will treat this as <quote>I want to operate on every file in 49 will treat this as <quote>I want to operate on every file in
50 this directory and its subdirectories</quote>.</para> 50 this directory and its subdirectories</quote>.</para>
51 51
52 &interaction.daily.files.add-dir; 52 &interaction.daily.files.add-dir;
53 53
54 <para id="x_1a8">Notice in this example that Mercurial printed the names of 54 <para id="x_1a8">Notice in this example that Mercurial printed
55 the files it added, whereas it didn't do so when we added the 55 the names of the files it added, whereas it didn't do so when
56 file named <filename>a</filename> in the earlier 56 we added the file named <filename>myfile.txt</filename> in the
57 example.</para> 57 earlier example.</para>
58 58
59 <para id="x_1a9">What's going on is that in the former case, we explicitly 59 <para id="x_1a9">What's going on is that in the former case, we explicitly
60 named the file to add on the command line, so the assumption 60 named the file to add on the command line. The assumption
61 that Mercurial makes in such cases is that you know what you 61 that Mercurial makes in such cases is that we know what we
62 were doing, and it doesn't print any output.</para> 62 are doing, and it doesn't print any output.</para>
63 63
64 <para id="x_1aa">However, when we <emphasis>imply</emphasis> the names of 64 <para id="x_1aa">However, when we <emphasis>imply</emphasis> the names of
65 files by giving the name of a directory, Mercurial takes the 65 files by giving the name of a directory, Mercurial takes the
66 extra step of printing the name of each file that it does 66 extra step of printing the name of each file that it does
67 something with. This makes it more clear what is happening, 67 something with. This makes it more clear what is happening,
68 and reduces the likelihood of a silent and nasty surprise. 68 and reduces the likelihood of a silent and nasty surprise.
69 This behavior is common to most Mercurial commands.</para> 69 This behavior is common to most Mercurial commands.</para>
70 70 </sect2>
71 </sect2> 71
72 <sect2> 72 <sect2>
73 <title>Mercurial tracks files, not directories</title> 73 <title>Mercurial tracks files, not directories</title>
74 74
75 <para id="x_1ab">Mercurial does not track directory information. Instead, 75 <para id="x_1ab">Mercurial does not track directory information. Instead,
76 it tracks the path to a file. Before creating a file, it 76 it tracks the path to a file. Before creating a file, it
100 &interaction.daily.files.hidden; 100 &interaction.daily.files.hidden;
101 101
102 <para id="x_1ae">Another way to tackle a need for an empty directory is to 102 <para id="x_1ae">Another way to tackle a need for an empty directory is to
103 simply create one in your automated build scripts before they 103 simply create one in your automated build scripts before they
104 will need it.</para> 104 will need it.</para>
105
106 </sect2> 105 </sect2>
107 </sect1> 106 </sect1>
107
108 <sect1> 108 <sect1>
109 <title>How to stop tracking a file</title> 109 <title>How to stop tracking a file</title>
110 110
111 <para id="x_1af">Once you decide that a file no longer belongs in your 111 <para id="x_1af">Once you decide that a file no longer belongs in your
112 repository, use the <command role="hg-cmd">hg remove</command> 112 repository, use the <command role="hg-cmd">hg remove</command>
113 command; this deletes the file, and tells Mercurial to stop 113 command. This deletes the file, and tells Mercurial to stop
114 tracking it. A removed file is represented in the output of 114 tracking it. A removed file is represented in the output of
115 <command role="hg-cmd">hg status</command> with a 115 <command role="hg-cmd">hg status</command> with a
116 <quote><literal>R</literal></quote>.</para> 116 <quote><literal>R</literal></quote>.</para>
117 117
118 &interaction.daily.files.remove; 118 &interaction.daily.files.remove;
138 the file, from the time of the next commit.</para> 138 the file, from the time of the next commit.</para>
139 </listitem></itemizedlist> 139 </listitem></itemizedlist>
140 <para id="x_1b4">Removing a file <emphasis>does not</emphasis> in any way 140 <para id="x_1b4">Removing a file <emphasis>does not</emphasis> in any way
141 alter the <emphasis>history</emphasis> of the file.</para> 141 alter the <emphasis>history</emphasis> of the file.</para>
142 142
143 <para id="x_1b5">If you update the working directory to a changeset in 143 <para id="x_1b5">If you update the working directory to a
144 which a file that you have removed was still tracked, it will 144 changeset that was committed when it was still tracking a file
145 reappear in the working directory, with the contents it had 145 that you later removed, the file will reappear in the working
146 when you committed that changeset. If you then update the 146 directory, with the contents it had when you committed that
147 working directory to a later changeset, in which the file had 147 changeset. If you then update the working directory to a
148 been removed, Mercurial will once again remove the file from 148 later changeset, in which the file had been removed, Mercurial
149 the working directory.</para> 149 will once again remove the file from the working
150 150 directory.</para>
151 </sect2> 151 </sect2>
152
152 <sect2> 153 <sect2>
153 <title>Missing files</title> 154 <title>Missing files</title>
154 155
155 <para id="x_1b6">Mercurial considers a file that you have deleted, but not 156 <para id="x_1b6">Mercurial considers a file that you have deleted, but not
156 used <command role="hg-cmd">hg remove</command> to delete, to 157 used <command role="hg-cmd">hg remove</command> to delete, to
175 <para id="x_1b8">On the other hand, if you deleted the missing file by 176 <para id="x_1b8">On the other hand, if you deleted the missing file by
176 accident, give <command role="hg-cmd">hg revert</command> the 177 accident, give <command role="hg-cmd">hg revert</command> the
177 name of the file to recover. It will reappear, in unmodified 178 name of the file to recover. It will reappear, in unmodified
178 form.</para> 179 form.</para>
179 180
180 &interaction.daily.files.recover-missing; 181 &interaction.daily.files.recover-missing;
181 182 </sect2>
182 </sect2> 183
183 <sect2> 184 <sect2>
184 <title>Aside: why tell Mercurial explicitly to remove a 185 <title>Aside: why tell Mercurial explicitly to remove a
185 file?</title> 186 file?</title>
186 187
187 <para id="x_1b9">You might wonder why Mercurial requires you to explicitly 188 <para id="x_1b9">You might wonder why Mercurial requires you to explicitly
190 pleased; Mercurial would notice the absence of the file 191 pleased; Mercurial would notice the absence of the file
191 automatically when you next ran a <command role="hg-cmd">hg 192 automatically when you next ran a <command role="hg-cmd">hg
192 commit</command>, and stop tracking the file. In practice, 193 commit</command>, and stop tracking the file. In practice,
193 this made it too easy to accidentally remove a file without 194 this made it too easy to accidentally remove a file without
194 noticing.</para> 195 noticing.</para>
195 196 </sect2>
196 </sect2> 197
197 <sect2> 198 <sect2>
198 <title>Useful shorthand&emdash;adding and removing files in one 199 <title>Useful shorthand&emdash;adding and removing files in one
199 step</title> 200 step</title>
200 201
201 <para id="x_1ba">Mercurial offers a combination command, <command 202 <para id="x_1ba">Mercurial offers a combination command, <command
208 also provides a <option role="hg-opt-commit">-A</option> 209 also provides a <option role="hg-opt-commit">-A</option>
209 option that performs this same add-and-remove, immediately 210 option that performs this same add-and-remove, immediately
210 followed by a commit.</para> 211 followed by a commit.</para>
211 212
212 &interaction.daily.files.commit-addremove; 213 &interaction.daily.files.commit-addremove;
213
214 </sect2> 214 </sect2>
215 </sect1> 215 </sect1>
216
216 <sect1> 217 <sect1>
217 <title>Copying files</title> 218 <title>Copying files</title>
218 219
219 <para id="x_1bc">Mercurial provides a <command role="hg-cmd">hg 220 <para id="x_1bc">Mercurial provides a <command role="hg-cmd">hg
220 copy</command> command that lets you make a new copy of a 221 copy</command> command that lets you make a new copy of a
270 repository, and merge the two heads, Mercurial will propagate 271 repository, and merge the two heads, Mercurial will propagate
271 the changes that we made locally to <filename>file</filename> 272 the changes that we made locally to <filename>file</filename>
272 into its copy, <filename>new-file</filename>.</para> 273 into its copy, <filename>new-file</filename>.</para>
273 274
274 &interaction.daily.copy.merge; 275 &interaction.daily.copy.merge;
275 276 </sect2>
276 </sect2> 277
277 <sect2 id="sec:daily:why-copy"> 278 <sect2 id="sec:daily:why-copy">
278 <title>Why should changes follow copies?</title> 279 <title>Why should changes follow copies?</title>
279 280
280 <para id="x_1c4">This behavior, of changes to a file propagating out to 281 <para id="x_1c4">This behavior&emdash;of changes to a file
281 copies of the file, might seem esoteric, but in most cases 282 propagating out to copies of the file&emdash;might seem
282 it's highly desirable.</para> 283 esoteric, but in most cases it's highly desirable.</para>
283 284
284 <para id="x_1c5">First of all, remember that this propagation 285 <para id="x_1c5">First of all, remember that this propagation
285 <emphasis>only</emphasis> happens when you merge. So if you 286 <emphasis>only</emphasis> happens when you merge. So if you
286 <command role="hg-cmd">hg copy</command> a file, and 287 <command role="hg-cmd">hg copy</command> a file, and
287 subsequently modify the original file during the normal course 288 subsequently modify the original file during the normal course
288 of your work, nothing will happen.</para> 289 of your work, nothing will happen.</para>
289 290
290 <para id="x_1c6">The second thing to know is that modifications will only 291 <para id="x_1c6">The second thing to know is that modifications will only
291 propagate across a copy as long as the repository that you're 292 propagate across a copy as long as the changeset that you're
292 pulling changes from <emphasis>doesn't know</emphasis> about 293 merging changes from <emphasis>hasn't yet seen</emphasis>
293 the copy.</para> 294 the copy.</para>
294 295
295 <para id="x_1c7">The reason that Mercurial does this is as follows. Let's 296 <para id="x_1c7">The reason that Mercurial does this is as follows. Let's
296 say I make an important bug fix in a source file, and commit 297 say I make an important bug fix in a source file, and commit
297 my changes. Meanwhile, you've decided to <command 298 my changes. Meanwhile, you've decided to <command
299 without knowing about the bug or having seen the fix, and you 300 without knowing about the bug or having seen the fix, and you
300 have started hacking on your copy of the file.</para> 301 have started hacking on your copy of the file.</para>
301 302
302 <para id="x_1c8">If you pulled and merged my changes, and Mercurial 303 <para id="x_1c8">If you pulled and merged my changes, and Mercurial
303 <emphasis>didn't</emphasis> propagate changes across copies, 304 <emphasis>didn't</emphasis> propagate changes across copies,
304 your source file would now contain the bug, and unless you 305 your new source file would now contain the bug, and unless you
305 remembered to propagate the bug fix by hand, the bug would 306 knew to propagate the bug fix by hand, the bug would
306 <emphasis>remain</emphasis> in your copy of the file.</para> 307 <emphasis>remain</emphasis> in your copy of the file.</para>
307 308
308 <para id="x_1c9">By automatically propagating the change that fixed the bug 309 <para id="x_1c9">By automatically propagating the change that fixed the bug
309 from the original file to the copy, Mercurial prevents this 310 from the original file to the copy, Mercurial prevents this
310 class of problem. To my knowledge, Mercurial is the 311 class of problem. To my knowledge, Mercurial is the
313 314
314 <para id="x_1ca">Once your change history has a record that the copy and 315 <para id="x_1ca">Once your change history has a record that the copy and
315 subsequent merge occurred, there's usually no further need to 316 subsequent merge occurred, there's usually no further need to
316 propagate changes from the original file to the copied file, 317 propagate changes from the original file to the copied file,
317 and that's why Mercurial only propagates changes across copies 318 and that's why Mercurial only propagates changes across copies
318 until this point, and no further.</para> 319 at the first merge, and not afterwards.</para>
319 320 </sect2>
320 </sect2> 321
321 <sect2> 322 <sect2>
322 <title>How to make changes <emphasis>not</emphasis> follow a 323 <title>How to make changes <emphasis>not</emphasis> follow a
323 copy</title> 324 copy</title>
324 325
325 <para id="x_1cb">If, for some reason, you decide that this business of 326 <para id="x_1cb">If, for some reason, you decide that this business of
333 decision that this behavior is not appropriate to your 334 decision that this behavior is not appropriate to your
334 specific case.</para> 335 specific case.</para>
335 336
336 </sect2> 337 </sect2>
337 <sect2> 338 <sect2>
338 <title>Behaviour of the <command role="hg-cmd">hg copy</command> 339 <title>Behavior of the <command role="hg-cmd">hg copy</command>
339 command</title> 340 command</title>
340 341
341 <para id="x_1cc">When you use the <command role="hg-cmd">hg copy</command> 342 <para id="x_1cc">When you use the <command role="hg-cmd">hg copy</command>
342 command, Mercurial makes a copy of each source file as it 343 command, Mercurial makes a copy of each source file as it
343 currently stands in the working directory. This means that if 344 currently stands in the working directory. This means that if
346 committed those changes, the new copy will also contain the 347 committed those changes, the new copy will also contain the
347 modifications you have made up until that point. (I find this 348 modifications you have made up until that point. (I find this
348 behavior a little counterintuitive, which is why I mention it 349 behavior a little counterintuitive, which is why I mention it
349 here.)</para> 350 here.)</para>
350 351
351 <para id="x_1cd">The <command role="hg-cmd">hg copy</command> command acts 352 <para id="x_1cd">The <command role="hg-cmd">hg copy</command>
352 similarly to the Unix <command>cp</command> command (you can 353 command acts similarly to the Unix <command>cp</command>
353 use the <command role="hg-cmd">hg cp</command> alias if you 354 command (you can use the <command role="hg-cmd">hg
354 prefer). The last argument is the 355 cp</command> alias if you prefer). We must supply two or
355 <emphasis>destination</emphasis>, and all prior arguments are 356 more arguments, of which the last is treated as the
356 <emphasis>sources</emphasis>. If you pass it a single file as 357 <emphasis>destination</emphasis>, and all others are
357 the source, and the destination does not exist, it creates a 358 <emphasis>sources</emphasis>.</para>
358 new file with that name.</para> 359
360 <para>If you pass <command role="hg-cmd">hg copy</command> a
361 single file as the source, and the destination does not exist,
362 it creates a new file with that name.</para>
359 363
360 &interaction.daily.copy.simple; 364 &interaction.daily.copy.simple;
361 365
362 <para id="x_1ce">If the destination is a directory, Mercurial copies its 366 <para id="x_1ce">If the destination is a directory, Mercurial copies its
363 sources into that directory.</para> 367 sources into that directory.</para>
373 <para id="x_1d0">If the source and destination are both directories, the 377 <para id="x_1d0">If the source and destination are both directories, the
374 source tree is recreated in the destination directory.</para> 378 source tree is recreated in the destination directory.</para>
375 379
376 &interaction.daily.copy.dir-src-dest; 380 &interaction.daily.copy.dir-src-dest;
377 381
378 <para id="x_1d1">As with the <command role="hg-cmd">hg rename</command> 382 <para id="x_1d1">As with the <command role="hg-cmd">hg remove</command>
379 command, if you copy a file manually and then want Mercurial 383 command, if you copy a file manually and then want Mercurial
380 to know that you've copied the file, simply use the <option 384 to know that you've copied the file, simply use the <option
381 role="hg-opt-copy">--after</option> option to <command 385 role="hg-opt-copy">--after</option> option to <command
382 role="hg-cmd">hg copy</command>.</para> 386 role="hg-cmd">hg copy</command>.</para>
383 387
384 &interaction.daily.copy.after; 388 &interaction.daily.copy.after;
385
386 </sect2> 389 </sect2>
387 </sect1> 390 </sect1>
391
388 <sect1> 392 <sect1>
389 <title>Renaming files</title> 393 <title>Renaming files</title>
390 394
391 <para id="x_1d2">It's rather more common to need to rename a file than to 395 <para id="x_1d2">It's rather more common to need to rename a file than to
392 make a copy of it. The reason I discussed the <command 396 make a copy of it. The reason I discussed the <command
424 respects, the behavior of the <command role="hg-cmd">hg 428 respects, the behavior of the <command role="hg-cmd">hg
425 rename</command> command, and the options it accepts, are 429 rename</command> command, and the options it accepts, are
426 similar to the <command role="hg-cmd">hg copy</command> 430 similar to the <command role="hg-cmd">hg copy</command>
427 command.</para> 431 command.</para>
428 432
433 <para>If you're familiar with the Unix command line, you'll be
434 glad to know that <command role="hg-cmd">hg rename</command>
435 command can be invoked as <command role="hg-cmd">hg
436 mv</command>.</para>
437
429 <sect2> 438 <sect2>
430 <title>Renaming files and merging changes</title> 439 <title>Renaming files and merging changes</title>
431 440
432 <para id="x_1d7">Since Mercurial's rename is implemented as 441 <para id="x_1d7">Since Mercurial's rename is implemented as
433 copy-and-remove, the same propagation of changes happens when 442 copy-and-remove, the same propagation of changes happens when
444 you can perhaps nod and say <quote>yes, that might be 453 you can perhaps nod and say <quote>yes, that might be
445 useful,</quote> it should be clear that having them follow a 454 useful,</quote> it should be clear that having them follow a
446 rename is definitely important. Without this facility, it 455 rename is definitely important. Without this facility, it
447 would simply be too easy for changes to become orphaned when 456 would simply be too easy for changes to become orphaned when
448 files are renamed.</para> 457 files are renamed.</para>
449 458 </sect2>
450 </sect2> 459
451 <sect2> 460 <sect2>
452 <title>Divergent renames and merging</title> 461 <title>Divergent renames and merging</title>
453 462
454 <para id="x_1da">The case of diverging names occurs when two developers 463 <para id="x_1da">The case of diverging names occurs when two developers
455 start with a file&emdash;let's call it 464 start with a file&emdash;let's call it
461 <para id="x_1db">Anne renames the file to <filename>bar</filename>.</para> 470 <para id="x_1db">Anne renames the file to <filename>bar</filename>.</para>
462 471
463 &interaction.rename.divergent.rename.anne; 472 &interaction.rename.divergent.rename.anne;
464 473
465 <para id="x_1dc">Meanwhile, Bob renames it to 474 <para id="x_1dc">Meanwhile, Bob renames it to
466 <filename>quux</filename>.</para> 475 <filename>quux</filename>. (Remember that <command
476 role="hg-cmd">hg mv</command> is an alias for <command
477 role="hg-cmd">hg rename</command>.)</para>
467 478
468 &interaction.rename.divergent.rename.bob; 479 &interaction.rename.divergent.rename.bob;
469 480
470 <para id="x_1dd">I like to think of this as a conflict because each 481 <para id="x_1dd">I like to think of this as a conflict because each
471 developer has expressed different intentions about what the 482 developer has expressed different intentions about what the
476 <emphasis>both</emphasis> names when it merges changesets that 487 <emphasis>both</emphasis> names when it merges changesets that
477 contain divergent renames.</para> 488 contain divergent renames.</para>
478 489
479 &interaction.rename.divergent.merge; 490 &interaction.rename.divergent.merge;
480 491
481 <para id="x_1df">Notice that Mercurial does warn about the divergent 492 <para id="x_1df">Notice that while Mercurial warns about the divergent
482 renames, but it leaves it up to you to do something about the 493 renames, it leaves it up to you to do something about the
483 divergence after the merge.</para> 494 divergence after the merge.</para>
484 495 </sect2>
485 </sect2> 496
486 <sect2> 497 <sect2>
487 <title>Convergent renames and merging</title> 498 <title>Convergent renames and merging</title>
488 499
489 <para id="x_1e0">Another kind of rename conflict occurs when two people 500 <para id="x_1e0">Another kind of rename conflict occurs when two people
490 choose to rename different <emphasis>source</emphasis> files 501 choose to rename different <emphasis>source</emphasis> files
491 to the same <emphasis>destination</emphasis>. In this case, 502 to the same <emphasis>destination</emphasis>. In this case,
492 Mercurial runs its normal merge machinery, and lets you guide 503 Mercurial runs its normal merge machinery, and lets you guide
493 it to a suitable resolution.</para> 504 it to a suitable resolution.</para>
494 505 </sect2>
495 </sect2> 506
496 <sect2> 507 <sect2>
497 <title>Other name-related corner cases</title> 508 <title>Other name-related corner cases</title>
498 509
499 <para id="x_1e1">Mercurial has a longstanding bug in which it fails to 510 <para id="x_1e1">Mercurial has a longstanding bug in which it fails to
500 handle a merge where one side has a file with a given name, 511 handle a merge where one side has a file with a given name,
505 516
506 &interaction.issue29.go; 517 &interaction.issue29.go;
507 518
508 </sect2> 519 </sect2>
509 </sect1> 520 </sect1>
521
510 <sect1> 522 <sect1>
511 <title>Recovering from mistakes</title> 523 <title>Recovering from mistakes</title>
512 524
513 <para id="x_1e2">Mercurial has some useful commands that will help you to 525 <para id="x_1e2">Mercurial has some useful commands that will help you to
514 recover from some common mistakes.</para> 526 recover from some common mistakes.</para>
521 while the file won't be touched in any way, it won't be tracked 533 while the file won't be touched in any way, it won't be tracked
522 for adding by Mercurial any longer, either. You can also use 534 for adding by Mercurial any longer, either. You can also use
523 <command role="hg-cmd">hg revert</command> to get rid of 535 <command role="hg-cmd">hg revert</command> to get rid of
524 erroneous changes to a file.</para> 536 erroneous changes to a file.</para>
525 537
526 <para id="x_1e4">It's useful to remember that the <command role="hg-cmd">hg 538 <para id="x_1e4">It's good to remember that the <command role="hg-cmd">hg
527 revert</command> command is useful for changes that you have 539 revert</command> command is useful for changes that you have
528 not yet committed. Once you've committed a change, if you 540 not yet committed. Once you've committed a change, if you
529 decide it was a mistake, you can still do something about it, 541 decide it was a mistake, you can still do something about it,
530 though your options may be more limited.</para> 542 though your options may be more limited.</para>
531 543
532 <para id="x_1e5">For more information about the <command 544 <para id="x_1e5">For more information about the <command
533 role="hg-cmd">hg revert</command> command, and details about 545 role="hg-cmd">hg revert</command> command, and details about
534 how to deal with changes you have already committed, see <xref 546 how to deal with changes you have already committed, see <xref
535 linkend="chap:undo"/>.</para> 547 linkend="chap:undo"/>.</para>
536 548 </sect1>
549
550 <sect1>
551 <title>Dealing with tricky merges</title>
552
553 <para>In a complicated or large project, it's not unusual for a
554 merge of two changesets to result in some headaches. Suppose
555 there's a big source file that's been extensively edited by each
556 side of a merge: this is almost inevitably going to result in
557 conflicts, some of which can take a few tries to sort
558 out.</para>
559
560 <para>Let's develop a simple case of this and see how to deal with
561 it. We'll start off with a repository containing one file, and
562 clone it twice.</para>
563
564 &interaction.ch04-resolve.init;
565
566 <para>In one clone, we'll modify the file in one way.</para>
567
568 &interaction.ch04-resolve.left;
569
570 <para>In another, we'll modify the file differently.</para>
571
572 &interaction.ch04-resolve.right;
573
574 <para>Next, we'll pull each set of changes into our original
575 repo.</para>
576
577 &interaction.ch04-resolve.pull;
578
579 <para>We expect our repository to now contain two heads.</para>
580
581 &interaction.ch04-resolve.heads;
582
583 <para>Normally, if we run <command role="hg-cmd">hg
584 merge</command> at this point, it will drop us into a GUI that
585 will let us manually resolve the conflicting edits to
586 <filename>myfile.txt</filename>. However, to simplify things
587 for presentation here, we'd like the merge to fail immediately
588 instead. Here's one way we can do so.</para>
589
590 &interaction.ch04-resolve.export;
591
592 <para>We've told Mercurial's merge machinery to run the command
593 <command>false</command> (which, as we desire, fails
594 immediately) if it detects a merge that it can't sort out
595 automatically.</para>
596
597 <para>If we now fire up <command role="hg-cmd">hg
598 merge</command>, it should grind to a halt and report a
599 failure.</para>
600
601 &interaction.ch04-resolve.merge;
602
603 <para>Even if we don't notice that the merge failed, Mercurial
604 will prevent us from accidentally committing the result of a
605 failed merge.</para>
606
607 &interaction.ch04-resolve.cifail;
608
609 <para>When <command role="hg-cmd">hg commit</command> fails in
610 this case, it suggests that we use the unfamiliar <command
611 role="hg-cmd">hg resolve</command> command. As usual,
612 <command role="hg-cmd">hg help resolve</command> will print a
613 helpful synopsis.</para>
614
615 <sect2>
616 <title>File resolution states</title>
617
618 <para>When a merge occurs, most files will usually remain
619 unmodified. For each file where Mercurial has to do
620 something, it tracks the state of the file.</para>
621
622 <itemizedlist>
623 <listitem>
624 <para>A <emphasis>resolved</emphasis> file has been
625 successfully merged, either automatically by Mercurial or
626 manually with human intervention.</para>
627 </listitem>
628 <listitem>
629 <para>An <emphasis>unresolved</emphasis> file was not merged
630 successfully, and needs more attention.</para>
631 </listitem>
632 </itemizedlist>
633
634 <para>If Mercurial sees <emphasis>any</emphasis> file in the
635 unresolved state after a merge, it considers the merge to have
636 failed. Fortunately, we do not need to restart the entire
637 merge from scratch.</para>
638
639 <para>The <option role="hg-opt-resolve">--list</option> or
640 <option role="hg-opt-resolve">-l</option> option to <command
641 role="hg-cmd">hg resolve</command> prints out the state of
642 each merged file.</para>
643
644 &interaction.ch04-resolve.list;
645
646 <para>In the output from <command role="hg-cmd">hg
647 resolve</command>, a resolved file is marked with
648 <literal>R</literal>, while an unresolved file is marked with
649 <literal>U</literal>. If any files are listed with
650 <literal>U</literal>, we know that an attempt to commit the
651 results of the merge will fail.</para>
652 </sect2>
653
654 <sect2>
655 <title>Resolving a file merge</title>
656
657 <para>We have several options to move a file from the unresolved
658 into the resolved state. By far the most common is to rerun
659 <command role="hg-cmd">hg resolve</command>. If we pass the
660 names of individual files or directories, it will retry the
661 merges of any unresolved files present in those locations. We
662 can also pass the <option role="hg-opt-resolve">--all</option>
663 or <option role="hg-opt-resolve">-a</option> option, which
664 will retry the merges of <emphasis>all</emphasis> unresolved
665 files.</para>
666
667 <para>Mercurial also lets us modify the resolution state of a
668 file directly. We can manually mark a file as resolved using
669 the <option role="hg-opt-resolve">--mark</option> option, or
670 as unresolved using the <option
671 role="hg-opt-resolve">--unmark</option> option. This allows
672 us to clean up a particularly messy merge by hand, and to keep
673 track of our progress with each file as we go.</para>
674 </sect2>
537 </sect1> 675 </sect1>
538 </chapter> 676 </chapter>
539 677
540 <!-- 678 <!--
541 local variables: 679 local variables: