comparison en/ch08-branch.xml @ 666:8fcd44708f41

Uncomment all the mangled interaction examples.
author Bryan O'Sullivan <bos@serpentine.com>
date Mon, 09 Mar 2009 23:22:09 -0700
parents b90b024729f1
children 13513d2a128d
comparison
equal deleted inserted replaced
665:27043f385f3f 666:8fcd44708f41
26 <para>Once you decide that you'd like to call a particular 26 <para>Once you decide that you'd like to call a particular
27 revision a <quote>release</quote>, it's a good idea to record 27 revision a <quote>release</quote>, it's a good idea to record
28 the identity of that revision. This will let you reproduce that 28 the identity of that revision. This will let you reproduce that
29 release at a later date, for whatever purpose you might need at 29 release at a later date, for whatever purpose you might need at
30 the time (reproducing a bug, porting to a new platform, etc). 30 the time (reproducing a bug, porting to a new platform, etc).
31 <!-- &interaction.tag.init; --></para> 31 &interaction.tag.init;</para>
32 32
33 <para>Mercurial lets you give a permanent name to any revision 33 <para>Mercurial lets you give a permanent name to any revision
34 using the <command role="hg-cmd">hg tag</command> command. Not 34 using the <command role="hg-cmd">hg tag</command> command. Not
35 surprisingly, these names are called <quote>tags</quote>. <!-- 35 surprisingly, these names are called <quote>tags</quote>.</para>
36 &interaction.tag.tag; --></para> 36
37 &interaction.tag.tag;
37 38
38 <para>A tag is nothing more than a <quote>symbolic name</quote> 39 <para>A tag is nothing more than a <quote>symbolic name</quote>
39 for a revision. Tags exist purely for your convenience, so that 40 for a revision. Tags exist purely for your convenience, so that
40 you have a handy permanent way to refer to a revision; Mercurial 41 you have a handy permanent way to refer to a revision; Mercurial
41 doesn't interpret the tag names you use in any way. Neither 42 doesn't interpret the tag names you use in any way. Neither
56 57
57 <para>You can use the <command role="hg-cmd">hg tags</command> 58 <para>You can use the <command role="hg-cmd">hg tags</command>
58 command to display the tags present in your repository. In the 59 command to display the tags present in your repository. In the
59 output, each tagged revision is identified first by its name, 60 output, each tagged revision is identified first by its name,
60 then by revision number, and finally by the unique hash of the 61 then by revision number, and finally by the unique hash of the
61 revision. <!-- &interaction.tag.tags; --> Notice that 62 revision.</para>
62 <literal>tip</literal> is listed in the output of <command 63
63 role="hg-cmd">hg tags</command>. The <literal>tip</literal> 64 &interaction.tag.tags;
64 tag is a special <quote>floating</quote> tag, which always 65
65 identifies the newest revision in the repository.</para> 66 <para>Notice that <literal>tip</literal> is listed in the output
67 of <command role="hg-cmd">hg tags</command>. The
68 <literal>tip</literal> tag is a special <quote>floating</quote>
69 tag, which always identifies the newest revision in the
70 repository.</para>
66 71
67 <para>In the output of the <command role="hg-cmd">hg 72 <para>In the output of the <command role="hg-cmd">hg
68 tags</command> command, tags are listed in reverse order, by 73 tags</command> command, tags are listed in reverse order, by
69 revision number. This usually means that recent tags are listed 74 revision number. This usually means that recent tags are listed
70 before older tags. It also means that <literal>tip</literal> is 75 before older tags. It also means that <literal>tip</literal> is
71 always going to be the first tag listed in the output of 76 always going to be the first tag listed in the output of
72 <command role="hg-cmd">hg tags</command>.</para> 77 <command role="hg-cmd">hg tags</command>.</para>
73 78
74 <para>When you run <command role="hg-cmd">hg log</command>, if it 79 <para>When you run <command role="hg-cmd">hg log</command>, if it
75 displays a revision that has tags associated with it, it will 80 displays a revision that has tags associated with it, it will
76 print those tags. <!-- &interaction.tag.log; --></para> 81 print those tags.</para>
82
83 &interaction.tag.log;
77 84
78 <para>Any time you need to provide a revision ID to a Mercurial 85 <para>Any time you need to provide a revision ID to a Mercurial
79 command, the command will accept a tag name in its place. 86 command, the command will accept a tag name in its place.
80 Internally, Mercurial will translate your tag name into the 87 Internally, Mercurial will translate your tag name into the
81 corresponding revision ID, then use that. <!-- 88 corresponding revision ID, then use that.</para>
82 &interaction.tag.log.v1.0; --></para> 89
90 &interaction.tag.log.v1.0;
83 91
84 <para>There's no limit on the number of tags you can have in a 92 <para>There's no limit on the number of tags you can have in a
85 repository, or on the number of tags that a single revision can 93 repository, or on the number of tags that a single revision can
86 have. As a practical matter, it's not a great idea to have 94 have. As a practical matter, it's not a great idea to have
87 <quote>too many</quote> (a number which will vary from project 95 <quote>too many</quote> (a number which will vary from project
96 lot of noise if you were to tag every clean build. Instead, you 104 lot of noise if you were to tag every clean build. Instead, you
97 could tag failed builds (on the assumption that they're rare!), 105 could tag failed builds (on the assumption that they're rare!),
98 or simply not use tags to track buildability.</para> 106 or simply not use tags to track buildability.</para>
99 107
100 <para>If you want to remove a tag that you no longer want, use 108 <para>If you want to remove a tag that you no longer want, use
101 <command role="hg-cmd">hg tag --remove</command>. <!-- 109 <command role="hg-cmd">hg tag --remove</command>.</para>
102 &interaction.tag.remove; --> You can also modify a tag at any 110
103 time, so that it identifies a different revision, by simply 111 &interaction.tag.remove;
104 issuing a new <command role="hg-cmd">hg tag</command> command. 112
105 You'll have to use the <option role="hg-opt-tag">-f</option> 113 <para>You can also modify a tag at any time, so that it identifies
106 option to tell Mercurial that you <emphasis>really</emphasis> 114 a different revision, by simply issuing a new <command
107 want to update the tag. <!-- &interaction.tag.replace; --> There 115 role="hg-cmd">hg tag</command> command. You'll have to use the
108 will still be a permanent record of the previous identity of the 116 <option role="hg-opt-tag">-f</option> option to tell Mercurial
109 tag, but Mercurial will no longer use it. There's thus no 117 that you <emphasis>really</emphasis> want to update the
110 penalty to tagging the wrong revision; all you have to do is 118 tag.</para>
111 turn around and tag the correct revision once you discover your 119
112 error.</para> 120 &interaction.tag.replace;
121
122 <para>There will still be a permanent record of the previous
123 identity of the tag, but Mercurial will no longer use it.
124 There's thus no penalty to tagging the wrong revision; all you
125 have to do is turn around and tag the correct revision once you
126 discover your error.</para>
113 127
114 <para>Mercurial stores tags in a normal revision-controlled file 128 <para>Mercurial stores tags in a normal revision-controlled file
115 in your repository. If you've created any tags, you'll find 129 in your repository. If you've created any tags, you'll find
116 them in a file named <filename 130 them in a file named <filename
117 role="special">.hgtags</filename>. When you run the <command 131 role="special">.hgtags</filename>. When you run the <command
118 role="hg-cmd">hg tag</command> command, Mercurial modifies 132 role="hg-cmd">hg tag</command> command, Mercurial modifies
119 this file, then automatically commits the change to it. This 133 this file, then automatically commits the change to it. This
120 means that every time you run <command role="hg-cmd">hg 134 means that every time you run <command role="hg-cmd">hg
121 tag</command>, you'll see a corresponding changeset in the 135 tag</command>, you'll see a corresponding changeset in the
122 output of <command role="hg-cmd">hg log</command>. <!-- 136 output of <command role="hg-cmd">hg log</command>.</para>
123 &interaction.tag.tip; --></para> 137
138 &interaction.tag.tip;
124 139
125 <sect2> 140 <sect2>
126 <title>Handling tag conflicts during a merge</title> 141 <title>Handling tag conflicts during a merge</title>
127 142
128 <para>You won't often need to care about the <filename 143 <para>You won't often need to care about the <filename
245 branch in Mercurial is in a dedicated repository. If you have 260 branch in Mercurial is in a dedicated repository. If you have
246 an existing shared repository&emdash;let's call it 261 an existing shared repository&emdash;let's call it
247 <literal>myproject</literal>&emdash;that reaches a 262 <literal>myproject</literal>&emdash;that reaches a
248 <quote>1.0</quote> milestone, you can start to prepare for 263 <quote>1.0</quote> milestone, you can start to prepare for
249 future maintenance releases on top of version 1.0 by tagging the 264 future maintenance releases on top of version 1.0 by tagging the
250 revision from which you prepared the 1.0 release. <!-- 265 revision from which you prepared the 1.0 release.</para>
251 &interaction.branch-repo.tag; --> You can then clone a new 266
252 shared <literal>myproject-1.0.1</literal> repository as of that 267 &interaction.branch-repo.tag;
253 tag. <!-- &interaction.branch-repo.clone; --></para> 268
269 <para>You can then clone a new shared
270 <literal>myproject-1.0.1</literal> repository as of that
271 tag.</para>
272
273 &interaction.branch-repo.clone;
254 274
255 <para>Afterwards, if someone needs to work on a bug fix that ought 275 <para>Afterwards, if someone needs to work on a bug fix that ought
256 to go into an upcoming 1.0.1 minor release, they clone the 276 to go into an upcoming 1.0.1 minor release, they clone the
257 <literal>myproject-1.0.1</literal> repository, make their 277 <literal>myproject-1.0.1</literal> repository, make their
258 changes, and push them back. <!-- 278 changes, and push them back.</para>
259 &interaction.branch-repo.bugfix; --> Meanwhile, development for 279
280 &interaction.branch-repo.bugfix;
281
282 <para>Meanwhile, development for
260 the next major release can continue, isolated and unabated, in 283 the next major release can continue, isolated and unabated, in
261 the <literal>myproject</literal> repository. <!-- 284 the <literal>myproject</literal> repository.</para>
262 &interaction.branch-repo.new; --></para> 285
286 &interaction.branch-repo.new;
263 287
264 </sect1> 288 </sect1>
265 <sect1> 289 <sect1>
266 <title>Don't repeat yourself: merging across branches</title> 290 <title>Don't repeat yourself: merging across branches</title>
267 291
273 help you to manage these bugfixes without duplicating your 297 help you to manage these bugfixes without duplicating your
274 work.</para> 298 work.</para>
275 299
276 <para>In the simplest instance, all you need to do is pull changes 300 <para>In the simplest instance, all you need to do is pull changes
277 from your maintenance branch into your local clone of the target 301 from your maintenance branch into your local clone of the target
278 branch. <!-- &interaction.branch-repo.pull; --> You'll then need 302 branch.</para>
279 to merge the heads of the two branches, and push back to the 303
280 main branch. <!-- &interaction.branch-repo.merge; --></para> 304 &interaction.branch-repo.pull;
305
306 <para>You'll then need to merge the heads of the two branches, and
307 push back to the main branch.</para>
308
309 &interaction.branch-repo.merge;
281 310
282 </sect1> 311 </sect1>
283 <sect1> 312 <sect1>
284 <title>Naming branches within one repository</title> 313 <title>Naming branches within one repository</title>
285 314
316 the branch named <literal>default</literal>.</para> 345 the branch named <literal>default</literal>.</para>
317 346
318 <para>To start working with named branches, use the <command 347 <para>To start working with named branches, use the <command
319 role="hg-cmd">hg branches</command> command. This command 348 role="hg-cmd">hg branches</command> command. This command
320 lists the named branches already present in your repository, 349 lists the named branches already present in your repository,
321 telling you which changeset is the tip of each. <!-- 350 telling you which changeset is the tip of each.</para>
322 &interaction.branch-named.branches; --> Since you haven't 351
323 created any named branches yet, the only one that exists is 352 &interaction.branch-named.branches;
324 <literal>default</literal>.</para> 353
354 <para>Since you haven't created any named branches yet, the only
355 one that exists is <literal>default</literal>.</para>
325 356
326 <para>To find out what the <quote>current</quote> branch is, run 357 <para>To find out what the <quote>current</quote> branch is, run
327 the <command role="hg-cmd">hg branch</command> command, giving 358 the <command role="hg-cmd">hg branch</command> command, giving
328 it no arguments. This tells you what branch the parent of the 359 it no arguments. This tells you what branch the parent of the
329 current changeset is on. <!-- &interaction.branch-named.branch; 360 current changeset is on.</para>
330 --></para> 361
362 &interaction.branch-named.branch;
331 363
332 <para>To create a new branch, run the <command role="hg-cmd">hg 364 <para>To create a new branch, run the <command role="hg-cmd">hg
333 branch</command> command again. This time, give it one 365 branch</command> command again. This time, give it one
334 argument: the name of the branch you want to create. <!-- 366 argument: the name of the branch you want to create.</para>
335 &interaction.branch-named.create; --></para> 367
368 &interaction.branch-named.create;
336 369
337 <para>After you've created a branch, you might wonder what effect 370 <para>After you've created a branch, you might wonder what effect
338 the <command role="hg-cmd">hg branch</command> command has had. 371 the <command role="hg-cmd">hg branch</command> command has had.
339 What do the <command role="hg-cmd">hg status</command> and 372 What do the <command role="hg-cmd">hg status</command> and
340 <command role="hg-cmd">hg tip</command> commands report? <!-- 373 <command role="hg-cmd">hg tip</command> commands report?</para>
341 &interaction.branch-named.status; --> Nothing has changed in the 374
375 &interaction.branch-named.status;
376
377 <para>Nothing has changed in the
342 working directory, and there's been no new history created. As 378 working directory, and there's been no new history created. As
343 this suggests, running the <command role="hg-cmd">hg 379 this suggests, running the <command role="hg-cmd">hg
344 branch</command> command has no permanent effect; it only 380 branch</command> command has no permanent effect; it only
345 tells Mercurial what branch name to use the 381 tells Mercurial what branch name to use the
346 <emphasis>next</emphasis> time you commit a changeset.</para> 382 <emphasis>next</emphasis> time you commit a changeset.</para>
349 branch on which you committed. Once you've switched from the 385 branch on which you committed. Once you've switched from the
350 <literal>default</literal> branch to another and committed, 386 <literal>default</literal> branch to another and committed,
351 you'll see the name of the new branch show up in the output of 387 you'll see the name of the new branch show up in the output of
352 <command role="hg-cmd">hg log</command>, <command 388 <command role="hg-cmd">hg log</command>, <command
353 role="hg-cmd">hg tip</command>, and other commands that 389 role="hg-cmd">hg tip</command>, and other commands that
354 display the same kind of output. <!-- 390 display the same kind of output.</para>
355 &interaction.branch-named.commit; --> The <command 391
356 role="hg-cmd">hg log</command>-like commands will print the 392 &interaction.branch-named.commit;
357 branch name of every changeset that's not on the 393
394 <para>The <command role="hg-cmd">hg log</command>-like commands
395 will print the branch name of every changeset that's not on the
358 <literal>default</literal> branch. As a result, if you never 396 <literal>default</literal> branch. As a result, if you never
359 use named branches, you'll never see this information.</para> 397 use named branches, you'll never see this information.</para>
360 398
361 <para>Once you've named a branch and committed a change with that 399 <para>Once you've named a branch and committed a change with that
362 name, every subsequent commit that descends from that change 400 name, every subsequent commit that descends from that change
363 will inherit the same branch name. You can change the name of a 401 will inherit the same branch name. You can change the name of a
364 branch at any time, using the <command role="hg-cmd">hg 402 branch at any time, using the <command role="hg-cmd">hg
365 branch</command> command. <!-- 403 branch</command> command.</para>
366 &interaction.branch-named.rebranch; --> In practice, this is 404
367 something you won't do very often, as branch names tend to have 405 &interaction.branch-named.rebranch;
368 fairly long lifetimes. (This isn't a rule, just an 406
369 observation.)</para> 407 <para>In practice, this is something you won't do very often, as
408 branch names tend to have fairly long lifetimes. (This isn't a
409 rule, just an observation.)</para>
370 410
371 </sect1> 411 </sect1>
372 <sect1> 412 <sect1>
373 <title>Dealing with multiple named branches in a 413 <title>Dealing with multiple named branches in a
374 repository</title> 414 repository</title>
383 you may need to use the <option role="hg-opt-update">-C</option> 423 you may need to use the <option role="hg-opt-update">-C</option>
384 option to <command role="hg-cmd">hg update</command>.</para> 424 option to <command role="hg-cmd">hg update</command>.</para>
385 425
386 <para>This behaviour is a little subtle, so let's see it in 426 <para>This behaviour is a little subtle, so let's see it in
387 action. First, let's remind ourselves what branch we're 427 action. First, let's remind ourselves what branch we're
388 currently on, and what branches are in our repository. <!-- 428 currently on, and what branches are in our repository.</para>
389 &interaction.branch-named.parents; --> We're on the 429
390 <literal>bar</literal> branch, but there also exists an older 430 &interaction.branch-named.parents;
391 <command role="hg-cmd">hg foo</command> branch.</para> 431
432 <para>We're on the <literal>bar</literal> branch, but there also
433 exists an older <command role="hg-cmd">hg foo</command>
434 branch.</para>
392 435
393 <para>We can <command role="hg-cmd">hg update</command> back and 436 <para>We can <command role="hg-cmd">hg update</command> back and
394 forth between the tips of the <literal>foo</literal> and 437 forth between the tips of the <literal>foo</literal> and
395 <literal>bar</literal> branches without needing to use the 438 <literal>bar</literal> branches without needing to use the
396 <option role="hg-opt-update">-C</option> option, because this 439 <option role="hg-opt-update">-C</option> option, because this
397 only involves going backwards and forwards linearly through our 440 only involves going backwards and forwards linearly through our
398 change history. <!-- &interaction.branch-named.update-switchy; 441 change history.</para>
399 --></para> 442
443 &interaction.branch-named.update-switchy;
400 444
401 <para>If we go back to the <literal>foo</literal> branch and then 445 <para>If we go back to the <literal>foo</literal> branch and then
402 run <command role="hg-cmd">hg update</command>, it will keep us 446 run <command role="hg-cmd">hg update</command>, it will keep us
403 on <literal>foo</literal>, not move us to the tip of 447 on <literal>foo</literal>, not move us to the tip of
404 <literal>bar</literal>. <!-- 448 <literal>bar</literal>.</para>
405 &interaction.branch-named.update-nothing; --></para> 449
450 &interaction.branch-named.update-nothing;
406 451
407 <para>Committing a new change on the <literal>foo</literal> branch 452 <para>Committing a new change on the <literal>foo</literal> branch
408 introduces a new head. <!-- 453 introduces a new head.</para>
409 &interaction.branch-named.foo-commit; --></para> 454
455 &interaction.branch-named.foo-commit;
410 456
411 </sect1> 457 </sect1>
412 <sect1> 458 <sect1>
413 <title>Branch names and merging</title> 459 <title>Branch names and merging</title>
414 460
437 result of a merge will be a single head on the 483 result of a merge will be a single head on the
438 <literal>foo</literal> branch, as you might hope.</para> 484 <literal>foo</literal> branch, as you might hope.</para>
439 485
440 <para>But if I'm working on the <literal>bar</literal> branch, and 486 <para>But if I'm working on the <literal>bar</literal> branch, and
441 I merge work from the <literal>foo</literal> branch, the result 487 I merge work from the <literal>foo</literal> branch, the result
442 will remain on the <literal>bar</literal> branch. <!-- 488 will remain on the <literal>bar</literal> branch.</para>
443 &interaction.branch-named.merge; --></para> 489
490 &interaction.branch-named.merge;
444 491
445 <para>To give a more concrete example, if I'm working on the 492 <para>To give a more concrete example, if I'm working on the
446 <literal>bleeding-edge</literal> branch, and I want to bring in 493 <literal>bleeding-edge</literal> branch, and I want to bring in
447 the latest fixes from the <literal>stable</literal> branch, 494 the latest fixes from the <literal>stable</literal> branch,
448 Mercurial will choose the <quote>right</quote> 495 Mercurial will choose the <quote>right</quote>