Mercurial > evolve
comparison docs/user-guide.rst @ 2931:83d2c9637e89
user-guide: edit pass
author | Ryan McElroy <rmcelroy@fb.com> |
---|---|
date | Wed, 30 Aug 2017 17:32:32 +0200 |
parents | 0683e3030316 |
children | 8406d9b06130 |
comparison
equal
deleted
inserted
replaced
2930:7932a0deae18 | 2931:83d2c9637e89 |
---|---|
24 *draft* phase by default: they are mutable. This means that they can | 24 *draft* phase by default: they are mutable. This means that they can |
25 be modified by Mercurial's existing history-editing commands | 25 be modified by Mercurial's existing history-editing commands |
26 (``rebase``, ``histedit``, etc.), and also by the ``evolve`` | 26 (``rebase``, ``histedit``, etc.), and also by the ``evolve`` |
27 extension. Specifically, ``evolve`` adds a number of commands that can | 27 extension. Specifically, ``evolve`` adds a number of commands that can |
28 be used to modify history: ``amend``, ``uncommit``, ``prune``, | 28 be used to modify history: ``amend``, ``uncommit``, ``prune``, |
29 ``fold``, and ``evolve``. Generally speaking, changesets remain in | 29 ``fold``, and ``evolve``. :: |
30 *draft* phase until they are pushed to another repository, at which | |
31 point they enter *public* phase. :: | |
32 | 30 |
33 $ hg commit -m 'implement feature X' | 31 $ hg commit -m 'implement feature X' |
34 $ hg phase -r . | 32 $ hg phase -r . |
35 1: draft | 33 1: draft |
36 | 34 |
37 (Strictly speaking, changesets only become public when they are pushed | 35 Generally speaking, changesets remain in *draft* phase until they are |
38 to a *publishing* repository. But all repositories are publishing by | 36 pushed to another repository, at which point they enter the *public* |
39 default; you have to explicitly configure repositories to be | 37 phase. (Strictly speaking, changesets only become public when they are |
38 pushed to a *publishing* repository. But all repositories are publishing | |
39 by default; you have to explicitly configure repositories to be | |
40 *non-publishing*. Non-publishing repositories are an advanced topic | 40 *non-publishing*. Non-publishing repositories are an advanced topic |
41 which we'll see when we get to `sharing mutable history`_.) | 41 which we'll see when we get to `sharing mutable history`_.) |
42 | 42 |
43 .. _`sharing mutable history`: sharing.html | 43 .. _`sharing mutable history`: sharing.html |
44 | 44 |
58 $ hg commit --amend -m 'implement feature Y' | 58 $ hg commit --amend -m 'implement feature Y' |
59 | 59 |
60 to create a new, amended changeset. The drawback of doing this with | 60 to create a new, amended changeset. The drawback of doing this with |
61 vanilla Mercurial is that your original, flawed, changeset is removed | 61 vanilla Mercurial is that your original, flawed, changeset is removed |
62 from the repository. This is *unsafe* history editing. It's probably | 62 from the repository. This is *unsafe* history editing. It's probably |
63 not too serious if all you did was fix a syntax error, but still. | 63 not too serious if all you did was fix a syntax error, but for deeper |
64 changes there can be more serious consequences to unsafe history editing. | |
64 | 65 |
65 .. figure:: figures/figure-ug01.svg | 66 .. figure:: figures/figure-ug01.svg |
66 | 67 |
67 Figure 1: unsafe history modification with core Mercurial (not | 68 Figure 1: unsafe history modification with core Mercurial (not |
68 using ``evolve``): the original revision 1 is destroyed. | 69 using ``evolve``): the original revision 1 is destroyed. |
69 | 70 |
70 (Incidentally, Mercurial's traditional history modification mechanism | 71 (Incidentally, Mercurial's traditional history modification mechanism |
71 isn't *really* unsafe: any changeset(s) removed from the repository | 72 isn't *really* unsafe: any changeset(s) removed from the repository |
72 are kept in a backup directory, so you can manually restore them later | 73 are kept in a backup directory, so you can manually restore them later |
73 if you change your mind. But it's awkward and inconvenient compared to | 74 if you change your mind. However, this mechanism is very awkward and |
74 the features provided by ``evolve`` and changeset obsolescence.) | 75 inconvenient compared to the features provided by ``evolve`` and |
76 changeset obsolescence.) | |
75 | 77 |
76 Life with ``evolve`` (basic usage) | 78 Life with ``evolve`` (basic usage) |
77 ---------------------------------- | 79 ---------------------------------- |
78 | 80 |
79 Once you enable the ``evolve`` extension, a number of features are | 81 Once you enable the ``evolve`` extension, a number of features are |
97 difference is that ``hg amend`` reuses the existing commit message by | 99 difference is that ``hg amend`` reuses the existing commit message by |
98 default, whereas ``hg commit --amend`` runs your editor if you don't | 100 default, whereas ``hg commit --amend`` runs your editor if you don't |
99 pass ``-m`` or ``-l``.) | 101 pass ``-m`` or ``-l``.) |
100 | 102 |
101 Under the hood, though, things are quite different. Mercurial has | 103 Under the hood, though, things are quite different. Mercurial has |
102 simply marked the old changeset *obsolete*, replacing it with a new | 104 simply marked the old changeset as *obsolete*, replacing it with a new |
103 one. We'll explore what this means in detail later, after working | 105 one. We'll explore what this means in detail later, after working |
104 through a few more examples. | 106 through a few more examples. |
105 | 107 |
106 Example 4: Prune an unwanted changeset | 108 Example 4: Prune an unwanted changeset |
107 ====================================== | 109 ====================================== |
190 8:be6d5bc8e4cc step 2 | 192 8:be6d5bc8e4cc step 2 |
191 9:35f432d9f7c1 step 3 | 193 9:35f432d9f7c1 step 3 |
192 | 194 |
193 and fold them:: | 195 and fold them:: |
194 | 196 |
195 $ hg fold -m 'fix bug 64' -r 7:: | 197 $ hg fold -m 'fix bug 64' -r 7:: --exact |
196 3 changesets folded | 198 3 changesets folded |
197 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | 199 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
198 | 200 |
199 This time, Mercurial marks three changesets obsolete, replacing them | 201 This time, Mercurial marks three changesets obsolete, replacing them |
200 all with a single *successor*. | 202 all with a single *successor*. |
212 understand the more advanced use cases we'll see later. | 214 understand the more advanced use cases we'll see later. |
213 | 215 |
214 When you have the ``evolve`` extension enabled, all history | 216 When you have the ``evolve`` extension enabled, all history |
215 modification uses the same underlying mechanism: the original | 217 modification uses the same underlying mechanism: the original |
216 changesets are marked *obsolete* and replaced by zero or more | 218 changesets are marked *obsolete* and replaced by zero or more |
217 *successors*. The obsolete changesets are the *precursors* of their | 219 *successors*. The obsolete changesets are the *predecessors* of their |
218 successors. This applies equally to built-in commands (``commit | 220 successors. This applies equally to built-in commands (``commit |
219 --amend``), commands added by ``evolve`` (``amend``, ``prune``, | 221 --amend``), commands added by ``evolve`` (``amend``, ``prune``, |
220 ``uncommit``, ``fold``), and commands provided by other extensions | 222 ``uncommit``, ``fold``), and commands provided by other extensions |
221 (``rebase``, ``histedit``). | 223 (``rebase``, ``histedit``). |
222 | 224 |
230 ================================= | 232 ================================= |
231 | 233 |
232 Consider Example 2, amending a changeset with ``evolve``. We saw above | 234 Consider Example 2, amending a changeset with ``evolve``. We saw above |
233 that you can do this using the exact same command-line syntax as core | 235 that you can do this using the exact same command-line syntax as core |
234 Mercurial, namely ``hg commit --amend``. But the implementation is | 236 Mercurial, namely ``hg commit --amend``. But the implementation is |
235 quite different, and Figure 2 shows how. | 237 quite different, as Figure 2 shows. |
236 | 238 |
237 .. figure:: figures/figure-ug02.svg | 239 .. figure:: figures/figure-ug02.svg |
238 | 240 |
239 Figure 2: safe history modification using ``evolve``: the original | 241 Figure 2: safe history modification using ``evolve``: the original |
240 revision 1 is preserved as an obsolete changeset. (The "temporary | 242 revision 1 is preserved as an obsolete changeset. (The "temporary |
241 amend commit", marked with T, is an implementation detail stemming | 243 amend commit", marked with T, is an implementation detail stemming |
242 from limitations in Mercurial's current merge machinery. Future | 244 from limitations in Mercurial's current merge machinery. Future |
243 versions of Mercurial will not create them.) | 245 versions of Mercurial will not create them.) |
244 | 246 |
245 In this case, the obsolete changesets are also *hidden*. That is the | 247 In this case, the obsolete changesets are also *hidden*. That is the |
246 usual end state for obsolete changesets. But many scenarios result in | 248 usual end state for obsolete changesets. However, many scenarios result |
247 obsolete changesets that are still visible, which indicates your | 249 in obsolete changesets that are still visible, which indicates your |
248 history modification work is not yet done. We'll see examples of that | 250 history modification work is not yet done. We'll see examples of that |
249 later, when we cover advanced usage. | 251 later, when we cover advanced usage. |
250 | 252 |
251 | 253 |
252 Understanding revision numbers and hidden changesets | 254 Understanding revision numbers and hidden changesets |
285 =========================================== | 287 =========================================== |
286 | 288 |
287 ``prune`` (example 4 above) is the simplest history modification | 289 ``prune`` (example 4 above) is the simplest history modification |
288 command provided by ``evolve``. All it does is mark the specified | 290 command provided by ``evolve``. All it does is mark the specified |
289 changeset(s) obsolete, with no successor/precursor relationships | 291 changeset(s) obsolete, with no successor/precursor relationships |
290 involved. (If the working directory parent was one of the obsolete | 292 involved. (If the working directory parent was one of the obsoleted |
291 changesets, ``prune`` updates back to a suitable ancestor.) | 293 changesets, ``prune`` updates back to a suitable ancestor.) |
292 | 294 |
293 .. figure:: figures/figure-ug03.svg | 295 .. figure:: figures/figure-ug03.svg |
294 | 296 |
295 Figure 3: pruning a changeset marks it obsolete with no successors. | 297 Figure 3: pruning a changeset marks it obsolete with no successors. |
297 Under the hood: Uncommit changes to certain files | 299 Under the hood: Uncommit changes to certain files |
298 ================================================= | 300 ================================================= |
299 | 301 |
300 In one sense, ``uncommit`` is a simplified version of ``amend``. Like | 302 In one sense, ``uncommit`` is a simplified version of ``amend``. Like |
301 ``amend``, it obsoletes one changeset and leaves it with a single | 303 ``amend``, it obsoletes one changeset and leaves it with a single |
302 successor. Unlike ``amend``, there is no ugly "temporary amend commit" | 304 successor. In another sense, ``uncommit`` is the inverse of ``amend``: |
303 cluttering up the repository. | 305 ``amend`` takes any uncommitted changes in the working dir and “adds” |
304 | |
305 In another sense, ``uncommit`` is the inverse of ``amend``: ``amend`` | |
306 takes any uncommitted changes in the working dir and “adds” | |
307 them to the working directory's parent changeset. (In reality, of | 306 them to the working directory's parent changeset. (In reality, of |
308 course, it creates a successor changeset, marking the original | 307 course, it creates a successor changeset, marking the original |
309 obsolete.) In contrast, ``uncommit`` takes some changes in the working | 308 obsolete.) In contrast, ``uncommit`` takes some changes in the working |
310 directory's parent and moves them to the working dir, creating a new | 309 directory's parent and moves them to the working dir, creating a new |
311 successor changeset in the process. Figure 4 illustrates. | 310 successor changeset in the process. Figure 4 illustrates. |
339 It's entirely possible to have obsolete changesets that are not | 338 It's entirely possible to have obsolete changesets that are not |
340 hidden. We'll see examples of that soon, when we create *unstable* | 339 hidden. We'll see examples of that soon, when we create *unstable* |
341 changesets. | 340 changesets. |
342 | 341 |
343 Note that all hidden changesets are obsolete: hidden is a subset of | 342 Note that all hidden changesets are obsolete: hidden is a subset of |
344 obsolete. | 343 obsolete. This is explained in more depth in the `concepts`_ section. |
345 | 344 |
345 .. _`concepts`: concepts.html | |
346 | 346 |
347 Life with ``evolve`` (advanced usage) | 347 Life with ``evolve`` (advanced usage) |
348 ------------------------------------- | 348 ------------------------------------- |
349 | 349 |
350 Now that you've got a solid understanding of how ``evolve`` works in | 350 Now that you've got a solid understanding of how ``evolve`` works in |
351 concert with changeset obsolescence, let's explore some more advanced | 351 concert with changeset obsolescence, let's explore some more advanced |
352 scenarios. All of these scenarios will involve *unstable* changesets, | 352 scenarios. All of these scenarios will involve *unstable* changesets, |
353 which is an unavoidable consequence of obsolescence. What really sets | 353 which is an unavoidable consequence of obsolescence. What really sets |
354 ``evolve`` apart from other history modification mechanisms is the | 354 ``evolve`` apart from other history modification mechanisms is the |
355 fact that it recognizes troubles like unstable changesets and provides | 355 fact that it recognizes troubles like unstable changesets and provides |
356 a consistent way for you to get out of trouble. | 356 a consistent way for you to get back to a stable repository. |
357 | 357 |
358 (Incidentally, there are two other types of trouble that changesets | 358 (Incidentally, there are two other types of troubles that changesets |
359 can get into with ``evolve``: they may be *divergent* or *bumped*. | 359 can get into with ``evolve``: they may be *divergent* or |
360 Both of those states are more likely to occur when `sharing mutable | 360 *bumped*. Both of those states are more likely to occur when |
361 history`_, so we won't see them in this user guide.) | 361 `sharing mutable history`_, so we won't cover them in this user guide.) |
362 | 362 |
363 .. _`sharing mutable history`: sharing.html | 363 .. _`sharing mutable history`: sharing.html |
364 | 364 |
365 | 365 |
366 Example 7: Amend an older changeset | 366 Example 7: Amend an older changeset |
367 =================================== | 367 =================================== |
368 | 368 |
369 Sometimes you don't notice your mistakes until after you have | 369 Sometimes you don't notice a mistake until after you have committed |
370 committed new changesets on top of them. :: | 370 new changesets on top of the changeset with the mistake. :: |
371 | 371 |
372 $ hg commit -m 'fix bug 17' # rev 11 (mistake here) | 372 $ hg commit -m 'fix bug 17' # rev 11 (mistake here) |
373 $ hg commit -m 'cleanup' # rev 12 | 373 $ hg commit -m 'cleanup' # rev 12 |
374 $ hg commit -m 'feature 23' # rev 13 | 374 $ hg commit -m 'feature 23' # rev 13 |
375 | 375 |
400 Figure 6: amending a changeset with descendants means the amended | 400 Figure 6: amending a changeset with descendants means the amended |
401 changeset is obsolete but remains visible; its non-obsolete | 401 changeset is obsolete but remains visible; its non-obsolete |
402 descendants are *unstable*. The temporary amend commit, revision | 402 descendants are *unstable*. The temporary amend commit, revision |
403 14, is hidden because it has no non-obsolete descendants. | 403 14, is hidden because it has no non-obsolete descendants. |
404 | 404 |
405 All non-obsolete descendants of an obsolete changeset are unstable. An | 405 All non-obsolete descendants of an obsolete changeset are considered |
406 interesting consequence of this is that revision 11 is still visible, | 406 unstable. An interesting consequence of this is that revision 11 is |
407 even though it is obsolete. Obsolete changesets with non-obsolete | 407 still visible, even though it is obsolete. Obsolete changesets with |
408 descendants are not hidden. | 408 non-obsolete descendants are not hidden. |
409 | 409 |
410 The fix is to *evolve* history:: | 410 The fix is to *evolve* history:: |
411 | 411 |
412 $ hg evolve --all | 412 $ hg evolve --all |
413 | 413 |
414 This is a separate step, not automatically part of ``hg amend``, | 414 This is a separate step, not automatically part of ``hg amend``, |
415 because there might be conflicts. If your amended changeset modifies a | 415 because there might be conflicts. If your amended changeset modifies a |
416 file that one of its descendants also modified, Mercurial has to fire | 416 file that one of its descendants also modified, Mercurial has to fire |
417 up your merge tool to resolve the conflict. More importantly, you have | 417 up your merge tool to resolve the conflict. More importantly, you have |
418 to switch contexts from "writing code" to "resolving conflicts". That | 418 to switch from "writing code" to "resolving conflicts". That can be an |
419 can be an expensive context switch, so Mercurial lets you decide when | 419 expensive context switch, so Mercurial lets you decide when to do it. |
420 to do it. | |
421 | 420 |
422 The end state, after ``evolve`` finishes, is that the original | 421 The end state, after ``evolve`` finishes, is that the original |
423 revisions (11-13) are obsolete and hidden. Their successor revisions | 422 revisions (11-13) are obsolete and hidden. Their successor revisions |
424 (15-17) replace them. | 423 (15-17) replace them. |
425 | 424 |
489 1 new unstable changesets | 488 1 new unstable changesets |
490 $ hg status | 489 $ hg status |
491 M file2.c | 490 M file2.c |
492 | 491 |
493 Now your repository has unstable changesets, so you need to evolve it. | 492 Now your repository has unstable changesets, so you need to evolve it. |
494 But ``hg evolve`` requires a clean working directory to resolve merge | 493 However, ``hg evolve`` requires a clean working directory to resolve merge |
495 conflicts, so you need to decide what to do with ``file2.c``. | 494 conflicts, so you need to decide what to do with ``file2.c``. |
496 | 495 |
497 In this case, the change to ``file2.c`` was a temporary debugging | 496 In this case, the change to ``file2.c`` was a temporary debugging |
498 hack, so we can discard it and immediately evolve the instability away:: | 497 hack, so we can discard it and immediately evolve the instability away:: |
499 | 498 |
523 $ hg commit -u dan -d '11 0' -m 'fix a bug' # rev 26 (oops) | 522 $ hg commit -u dan -d '11 0' -m 'fix a bug' # rev 26 (oops) |
524 $ echo 'new feature' >> file1.c | 523 $ echo 'new feature' >> file1.c |
525 $ hg commit -u dan -d '12 0' -m 'new feature' # rev 27 (fine) | 524 $ hg commit -u dan -d '12 0' -m 'new feature' # rev 27 (fine) |
526 | 525 |
527 As before, we update back to the flawed changeset (this time, | 526 As before, we update back to the flawed changeset (this time, |
528 revision 26) and ``uncommit``, leaving uncommitted changes to | 527 revision 26) and use ``uncommit``, leaving uncommitted changes to |
529 ``file2.c`` in the working dir:: | 528 ``file2.c`` in the working dir:: |
530 | 529 |
531 $ hg update -q 26 | 530 $ hg update -q 26 |
532 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | 531 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
533 $ hg uncommit -q file2.c # obsoletes rev 26, creates rev 28 | 532 $ hg uncommit -q file2.c # obsoletes rev 26, creates rev 28 |
534 1 new unstable changesets | 533 1 new unstable changesets |
535 $ hg status | 534 $ hg status |
536 M file2.c | 535 M file2.c |
537 | 536 |
538 This time, let's save that useful change before evolving:: | 537 This time, let's save that useful change before evolving:: |
539 | 538 |
540 $ hg commit -m 'useful tweak' # rev 29 | 539 $ hg commit -m 'useful tweak' # rev 29 |
541 | 540 |
542 Figure 11 shows the story so far: ``uncommit`` obsoleted revision 26 | 541 Figure 11 shows the story so far: ``uncommit`` obsoleted revision 26 |
543 and created revision 28, the successor of 26. Then we committed | 542 and created revision 28, the successor of 26. Then we committed |
544 revision 29, a child of 28. We still have to deal with the unstable | 543 revision 29, a child of 28. We still have to deal with the revision 27, |
545 revision 27. | 544 which is an unstable changeset. |
546 | 545 |
547 .. figure:: figures/figure-ug11.svg | 546 .. figure:: figures/figure-ug11.svg |
548 | 547 |
549 Figure 11: Uncommitting a file and then committing that change | 548 Figure 11: Uncommitting a file and then committing that change |
550 separately will soon result in a two-headed repository. | 549 separately will soon result in a two-headed repository. |
592 as ``REV``, and will be a successor of ``REV``. | 591 as ``REV``, and will be a successor of ``REV``. |
593 | 592 |
594 The current implementation of ``hg touch`` is not ideal, and is likely to | 593 The current implementation of ``hg touch`` is not ideal, and is likely to |
595 change in the future. Consider the history in Figure 12, where revision 27 | 594 change in the future. Consider the history in Figure 12, where revision 27 |
596 is obsolete and the child of 26, also obsolete. If we ``hg touch 27``, that | 595 is obsolete and the child of 26, also obsolete. If we ``hg touch 27``, that |
597 creates a new revision which is a non-obsolete child of 26—i.e., it is | 596 creates a new revision which is a non-obsolete child of 26—i.e., it is an |
598 unstable. It's also *divergent*, another type of trouble that we'll learn | 597 unstable. It's also *divergent*, another type of trouble that we'll learn |
599 about in the `next section`_. | 598 about in the `next section`_. |
600 | 599 |
601 .. _`next section`: sharing.html | 600 .. _`next section`: sharing.html |