Mercurial > evolve
annotate docs/user-guide.rst @ 4895:92d617c7be66 stable
tests: clean up test-metaedit.t
Mostly just artifacts from the times when it was one big test-evolve.t. All
completely unused nowadays.
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Wed, 09 Oct 2019 20:07:42 +0700 |
parents | 561e97db1cf7 |
children | 8beb44234b33 |
rev | line source |
---|---|
978 | 1 .. Copyright © 2014 Greg Ward <greg@gerg.ca> |
2 | |
3 ------------------ | |
4 Evolve: User Guide | |
5 ------------------ | |
6 | |
7 .. contents:: | |
8 | |
9 Life without ``evolve`` | |
10 ----------------------- | |
11 | |
12 Before we dive into learning about ``evolve``, let's look into some | |
13 features of core Mercurial that interact with ``evolve``. ``commit`` | |
14 affects ``evolve``, and ``evolve`` modifies how ``commit --amend`` | |
15 works. | |
16 | |
17 Example 1: Commit a new changeset | |
18 ================================= | |
19 | |
20 To create a new changeset, simply run ``hg commit`` as usual. | |
21 ``evolve`` does not change the behaviour of ``commit`` at all. | |
22 | |
23 However, it's important to understand that new changesets are in the | |
24 *draft* phase by default: they are mutable. This means that they can | |
25 be modified by Mercurial's existing history-editing commands | |
26 (``rebase``, ``histedit``, etc.), and also by the ``evolve`` | |
27 extension. Specifically, ``evolve`` adds a number of commands that can | |
28 be used to modify history: ``amend``, ``uncommit``, ``prune``, | |
2931 | 29 ``fold``, and ``evolve``. :: |
978 | 30 |
31 $ hg commit -m 'implement feature X' | |
32 $ hg phase -r . | |
33 1: draft | |
34 | |
2931 | 35 Generally speaking, changesets remain in *draft* phase until they are |
36 pushed to another repository, at which point they enter the *public* | |
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 | |
978 | 40 *non-publishing*. Non-publishing repositories are an advanced topic |
41 which we'll see when we get to `sharing mutable history`_.) | |
42 | |
43 .. _`sharing mutable history`: sharing.html | |
44 | |
45 Example 2: Amend a changeset (traditional) | |
46 ========================================== | |
47 | |
48 Imagine you've just committed a new changeset, and then you discover a | |
49 mistake. Maybe you forgot to run the tests and a failure slipped in. | |
50 You want to modify history so that you push one perfect changeset, | |
51 rather than one flawed changeset followed by an "oops" commit. (Or | |
52 perhaps you made a typo in the commit message—this is really feature | |
53 *Y*, not feature X. You can't fix that with a followup commit.) | |
54 | |
55 This is actually trivial with plain vanilla Mercurial since 2.2: fix | |
56 your mistake and run :: | |
57 | |
58 $ hg commit --amend -m 'implement feature Y' | |
59 | |
60 to create a new, amended changeset. The drawback of doing this with | |
61 vanilla Mercurial is that your original, flawed, changeset is removed | |
62 from the repository. This is *unsafe* history editing. It's probably | |
2931 | 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. | |
978 | 65 |
66 .. figure:: figures/figure-ug01.svg | |
67 | |
68 Figure 1: unsafe history modification with core Mercurial (not | |
69 using ``evolve``): the original revision 1 is destroyed. | |
70 | |
71 (Incidentally, Mercurial's traditional history modification mechanism | |
72 isn't *really* unsafe: any changeset(s) removed from the repository | |
73 are kept in a backup directory, so you can manually restore them later | |
2931 | 74 if you change your mind. However, this mechanism is very awkward and |
75 inconvenient compared to the features provided by ``evolve`` and | |
76 changeset obsolescence.) | |
978 | 77 |
78 Life with ``evolve`` (basic usage) | |
79 ---------------------------------- | |
80 | |
81 Once you enable the ``evolve`` extension, a number of features are | |
82 available to you. First, we're going to explore several examples of | |
83 painless, trouble-free history modification. | |
84 | |
85 Example 3: Amend a changeset (with ``evolve``) | |
86 ============================================== | |
87 | |
88 Outwardly, amending a changeset with ``evolve`` can look exactly the | |
89 same as it does with core Mercurial (example 2):: | |
90 | |
91 $ hg commit --amend -m 'implement feature Y' | |
92 | |
93 Alternately, you can use the new ``amend`` command added by | |
94 ``evolve``:: | |
95 | |
96 $ hg amend -m 'implement feature Y' | |
97 | |
98 (``hg amend`` is nearly synonymous with ``hg commit --amend``. The | |
99 difference is that ``hg amend`` reuses the existing commit message by | |
100 default, whereas ``hg commit --amend`` runs your editor if you don't | |
101 pass ``-m`` or ``-l``.) | |
102 | |
103 Under the hood, though, things are quite different. Mercurial has | |
2931 | 104 simply marked the old changeset as *obsolete*, replacing it with a new |
978 | 105 one. We'll explore what this means in detail later, after working |
106 through a few more examples. | |
107 | |
108 Example 4: Prune an unwanted changeset | |
109 ====================================== | |
110 | |
111 Sometimes you make a change, and then decide it was such a bad idea | |
112 that you don't want anyone to know about it. Or maybe it was a | |
113 debugging hack that you needed to keep around for a while, but do not | |
114 intend to ever push publicly. :: | |
115 | |
116 $ echo 'debug hack' >> file1.c | |
117 $ hg commit -m 'debug hack' | |
118 | |
119 In either case, ``hg prune`` is the answer. ``prune`` simply marks | |
120 changesets obsolete without creating any new changesets to replace | |
121 them:: | |
122 | |
123 $ hg prune . | |
124 1 changesets pruned | |
125 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
126 working directory now at 934359450037 | |
127 | |
128 Outwardly, it appears that your “debug hack” commit never happened; | |
129 we're right back where we started:: | |
130 | |
131 $ hg parents --template '{rev}:{node|short} {desc|firstline}\n' | |
132 3:934359450037 implement feature Y | |
133 | |
134 In reality, though, the “debug hack” is still there, obsolete and hidden. | |
135 | |
136 Example 5: Uncommit changes to certain files | |
137 ============================================ | |
138 | |
139 Occasionally you commit more than you intended: perhaps you made | |
140 unrelated changes to different files, and thus intend to commit | |
141 different files separately. :: | |
142 | |
143 $ echo 'relevant' >> file1.c | |
144 $ echo 'irrelevant' >> file2.c | |
145 | |
146 If you forget to specify filenames on the ``commit`` command line, | |
147 Mercurial commits all those changes together:: | |
148 | |
149 $ hg commit -m 'fix bug 234' # oops: too many files | |
150 | |
151 Luckily, this mistake is easy to fix with ``uncommit``:: | |
152 | |
153 $ hg uncommit file2.c | |
154 $ hg status | |
155 M file2.c | |
156 | |
157 Let's verify that the replacement changeset looks right (i.e., | |
158 modifies only ``file1.c``):: | |
159 | |
160 $ hg parents --template '{rev}:{node|short} {desc|firstline}\n{files}\n' | |
161 6:c8defeecf7a4 fix bug 234 | |
162 file1.c | |
163 | |
164 As before, the original flawed changeset is still there, but obsolete | |
165 and hidden. It won't be exchanged with other repositories by ``push``, | |
166 ``pull``, or ``clone``. | |
167 | |
168 Example 6: Fold multiple changesets together into one | |
169 ===================================================== | |
170 | |
171 If you're making extensive changes to fragile source code, you might | |
172 commit more frequently than normal so that you can fallback on a | |
173 known good state if one step goes badly. :: | |
174 | |
175 $ echo step1 >> file1.c | |
176 $ hg commit -m 'step 1' # revision 7 | |
177 $ echo step2 >> file1.c | |
178 $ hg commit -m 'step 2' # revision 8 | |
179 $ echo step3 >> file2.c | |
180 $ hg commit -m 'step 3' # revision 9 | |
181 | |
182 At the end of such a sequence, you often end up with a series of small | |
183 changesets that are tedious to review individually. It might make more | |
184 sense to combine them into a single changeset using the ``fold`` | |
185 command. | |
186 | |
187 To make sure we pass the right revisions to ``fold``, let's review the | |
188 changesets we just created, from revision 7:: | |
189 | |
190 $ hg log --template '{rev}:{node|short} {desc|firstline}\n' -r 7:: | |
191 7:05e61aab8294 step 1 | |
192 8:be6d5bc8e4cc step 2 | |
193 9:35f432d9f7c1 step 3 | |
194 | |
195 and fold them:: | |
196 | |
2931 | 197 $ hg fold -m 'fix bug 64' -r 7:: --exact |
978 | 198 3 changesets folded |
199 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
200 | |
201 This time, Mercurial marks three changesets obsolete, replacing them | |
202 all with a single *successor*. | |
203 | |
204 (You might be familiar with this operation under other names, like | |
205 *squash* or *collapse*.) | |
206 | |
207 Changeset obsolescence under the hood | |
208 ------------------------------------- | |
209 | |
1267
8cc6e90354a9
docs: tweak wording, punctuation for better readability
Greg Ward <greg@gerg.ca>
parents:
978
diff
changeset
|
210 So far, everything has gone just fine: we haven't run into merge |
978 | 211 conflicts or other trouble. Before we start exploring advanced usage |
212 that can run into trouble, let's step back and see what happens when | |
213 Mercurial marks changesets obsolete. That will make it much easier to | |
214 understand the more advanced use cases we'll see later. | |
215 | |
216 When you have the ``evolve`` extension enabled, all history | |
217 modification uses the same underlying mechanism: the original | |
218 changesets are marked *obsolete* and replaced by zero or more | |
2931 | 219 *successors*. The obsolete changesets are the *predecessors* of their |
978 | 220 successors. This applies equally to built-in commands (``commit |
221 --amend``), commands added by ``evolve`` (``amend``, ``prune``, | |
1267
8cc6e90354a9
docs: tweak wording, punctuation for better readability
Greg Ward <greg@gerg.ca>
parents:
978
diff
changeset
|
222 ``uncommit``, ``fold``), and commands provided by other extensions |
8cc6e90354a9
docs: tweak wording, punctuation for better readability
Greg Ward <greg@gerg.ca>
parents:
978
diff
changeset
|
223 (``rebase``, ``histedit``). |
978 | 224 |
225 Another way of looking at it is that obsolescence is second-order | |
226 version control, i.e. the history of your history. We'll cover this in | |
227 more detail (and mathematical precision) in the `concepts`_ guide. | |
228 | |
229 .. _`concepts`: concepts.html | |
230 | |
231 Under the hood: Amend a changeset | |
232 ================================= | |
233 | |
234 Consider Example 2, amending a changeset with ``evolve``. We saw above | |
235 that you can do this using the exact same command-line syntax as core | |
236 Mercurial, namely ``hg commit --amend``. But the implementation is | |
2931 | 237 quite different, as Figure 2 shows. |
978 | 238 |
239 .. figure:: figures/figure-ug02.svg | |
240 | |
241 Figure 2: safe history modification using ``evolve``: the original | |
4626
561e97db1cf7
docs: drop references to the old temporary commit that was created with amend
Matt Harbison <matt_harbison@yahoo.com>
parents:
4621
diff
changeset
|
242 revision 1 is preserved as an obsolete changeset. |
978 | 243 |
244 In this case, the obsolete changesets are also *hidden*. That is the | |
2931 | 245 usual end state for obsolete changesets. However, many scenarios result |
246 in obsolete changesets that are still visible, which indicates your | |
978 | 247 history modification work is not yet done. We'll see examples of that |
248 later, when we cover advanced usage. | |
249 | |
1268 | 250 |
251 Understanding revision numbers and hidden changesets | |
252 ==================================================== | |
253 | |
254 As the name implies, hidden changesets are normally not visible. If | |
255 you run ``hg log`` on the repository from Figure 2, Mercurial will | |
4626
561e97db1cf7
docs: drop references to the old temporary commit that was created with amend
Matt Harbison <matt_harbison@yahoo.com>
parents:
4621
diff
changeset
|
256 show revisions 0 and 2, but not 1. That's something you don't |
1268 | 257 see with plain vanilla Mercurial—normally, revision *N* is always |
258 followed by revision *N* + 1. | |
259 | |
260 This is just the visible manifestation of hidden changesets. If | |
4626
561e97db1cf7
docs: drop references to the old temporary commit that was created with amend
Matt Harbison <matt_harbison@yahoo.com>
parents:
4621
diff
changeset
|
261 revision 0 is followed by revision 2, that means there is a hidden |
561e97db1cf7
docs: drop references to the old temporary commit that was created with amend
Matt Harbison <matt_harbison@yahoo.com>
parents:
4621
diff
changeset
|
262 changeset, (1) in between. |
1268 | 263 |
264 To see those hidden changesets, use the ``--hidden`` option:: | |
978 | 265 |
1268 | 266 $ hg --hidden log --graph --template '{rev}:{node|short} {desc|firstline}\n' |
4626
561e97db1cf7
docs: drop references to the old temporary commit that was created with amend
Matt Harbison <matt_harbison@yahoo.com>
parents:
4621
diff
changeset
|
267 @ 2:934359450037 implement feature Y |
1268 | 268 | |
269 | x 1:fe0ecd3bd2a4 implement feature Y | |
270 |/ | |
271 o 0:08c4b6f4efc8 init | |
272 | |
273 Note that changeset IDs are still the permanent, immutable identifier | |
274 for changesets. Revision numbers are, as ever, a handy shorthand that | |
275 work in your local repository, but cannot be used across repositories. | |
276 They also have the useful property of showing when there are hidden | |
277 changesets lurking under the covers, which is why this document uses | |
278 revision numbers. | |
279 | |
978 | 280 |
281 Under the hood: Prune an unwanted changeset | |
282 =========================================== | |
283 | |
284 ``prune`` (example 4 above) is the simplest history modification | |
285 command provided by ``evolve``. All it does is mark the specified | |
4615
8406d9b06130
docs: change `precursors` references to `predecessors`
Matt Harbison <matt_harbison@yahoo.com>
parents:
2931
diff
changeset
|
286 changeset(s) obsolete, with no successor/predecessor relationships |
2931 | 287 involved. (If the working directory parent was one of the obsoleted |
978 | 288 changesets, ``prune`` updates back to a suitable ancestor.) |
289 | |
290 .. figure:: figures/figure-ug03.svg | |
291 | |
292 Figure 3: pruning a changeset marks it obsolete with no successors. | |
293 | |
294 Under the hood: Uncommit changes to certain files | |
295 ================================================= | |
296 | |
297 In one sense, ``uncommit`` is a simplified version of ``amend``. Like | |
298 ``amend``, it obsoletes one changeset and leaves it with a single | |
2931 | 299 successor. In another sense, ``uncommit`` is the inverse of ``amend``: |
300 ``amend`` takes any uncommitted changes in the working dir and “adds” | |
978 | 301 them to the working directory's parent changeset. (In reality, of |
302 course, it creates a successor changeset, marking the original | |
303 obsolete.) In contrast, ``uncommit`` takes some changes in the working | |
304 directory's parent and moves them to the working dir, creating a new | |
305 successor changeset in the process. Figure 4 illustrates. | |
306 | |
307 .. figure:: figures/figure-ug04.svg | |
308 | |
309 Figure 4: uncommit moves some of the changes from the working | |
310 directory parent into the working dir, preserving the remaining | |
311 changes as a new successor changeset. (N.B. revision 4 is not shown | |
312 here because it was marked obsolete in the previous example.) | |
313 | |
314 | |
315 Under the hood: Fold multiple changesets together into one | |
316 ========================================================== | |
317 | |
318 The last basic example is folding multiple changesets into one, which | |
319 marks multiple changesets obsolete, replacing them all with a single | |
320 successor. | |
321 | |
322 .. figure:: figures/figure-ug05.svg | |
323 | |
324 Figure 5: fold combines multiple changesets into a single | |
325 successor, marking the original (folded) changesets obsolete. | |
326 | |
327 | |
328 Obsolete is not hidden | |
329 ====================== | |
330 | |
1269
250835154f8f
docs: explain that obsolete is not hidden
Greg Ward <greg@gerg.ca>
parents:
1268
diff
changeset
|
331 So far, every obsolete changeset we have seen is also hidden. However, |
250835154f8f
docs: explain that obsolete is not hidden
Greg Ward <greg@gerg.ca>
parents:
1268
diff
changeset
|
332 these are *not* the same thing—that's why they have different names. |
250835154f8f
docs: explain that obsolete is not hidden
Greg Ward <greg@gerg.ca>
parents:
1268
diff
changeset
|
333 It's entirely possible to have obsolete changesets that are not |
4618
803d32f4e498
docs: change `unstable` references to `orphan`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4616
diff
changeset
|
334 hidden. We'll see examples of that soon, when we create *orphan* |
1269
250835154f8f
docs: explain that obsolete is not hidden
Greg Ward <greg@gerg.ca>
parents:
1268
diff
changeset
|
335 changesets. |
250835154f8f
docs: explain that obsolete is not hidden
Greg Ward <greg@gerg.ca>
parents:
1268
diff
changeset
|
336 |
250835154f8f
docs: explain that obsolete is not hidden
Greg Ward <greg@gerg.ca>
parents:
1268
diff
changeset
|
337 Note that all hidden changesets are obsolete: hidden is a subset of |
2931 | 338 obsolete. This is explained in more depth in the `concepts`_ section. |
978 | 339 |
2931 | 340 .. _`concepts`: concepts.html |
978 | 341 |
342 Life with ``evolve`` (advanced usage) | |
343 ------------------------------------- | |
344 | |
345 Now that you've got a solid understanding of how ``evolve`` works in | |
346 concert with changeset obsolescence, let's explore some more advanced | |
4618
803d32f4e498
docs: change `unstable` references to `orphan`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4616
diff
changeset
|
347 scenarios. All of these scenarios will involve *orphan* changesets, |
978 | 348 which is an unavoidable consequence of obsolescence. What really sets |
349 ``evolve`` apart from other history modification mechanisms is the | |
4618
803d32f4e498
docs: change `unstable` references to `orphan`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4616
diff
changeset
|
350 fact that it recognizes instability like orphan changesets and provides |
2931 | 351 a consistent way for you to get back to a stable repository. |
978 | 352 |
4616
a78310b900e3
docs: change `troubles` references to `instability`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4615
diff
changeset
|
353 (Incidentally, there are two other types of instability that changesets |
4620
a05bfdf372fb
docs: change `divergent` references to `content-divergent`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4618
diff
changeset
|
354 can get into with ``evolve``: they may be *content-divergent* or |
4621
8784dfc6537c
docs: change `bumped` references to `phase-divergent`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4620
diff
changeset
|
355 *phase-divergent*. Both of those states are more likely to occur when |
2931 | 356 `sharing mutable history`_, so we won't cover them in this user guide.) |
978 | 357 |
358 .. _`sharing mutable history`: sharing.html | |
359 | |
360 | |
361 Example 7: Amend an older changeset | |
362 =================================== | |
363 | |
2931 | 364 Sometimes you don't notice a mistake until after you have committed |
365 new changesets on top of the changeset with the mistake. :: | |
978 | 366 |
367 $ hg commit -m 'fix bug 17' # rev 11 (mistake here) | |
368 $ hg commit -m 'cleanup' # rev 12 | |
369 $ hg commit -m 'feature 23' # rev 13 | |
370 | |
371 Traditionally, your only option is to commit an "oops" changeset that | |
372 fixes your mistake. That works, of course, but it makes you look bad: | |
373 you made a mistake, and the record of that mistake is recorded in | |
374 history for all eternity. (If the mistake was in the commit message, | |
1267
8cc6e90354a9
docs: tweak wording, punctuation for better readability
Greg Ward <greg@gerg.ca>
parents:
978
diff
changeset
|
375 too bad: you cannot fix it.) |
978 | 376 |
377 More subtly, there now exist changesets that are *worse* than what | |
378 came before—the code no longer builds, the tests don't pass, or | |
1267
8cc6e90354a9
docs: tweak wording, punctuation for better readability
Greg Ward <greg@gerg.ca>
parents:
978
diff
changeset
|
379 similar. Anyone reviewing these patches will waste time on the error |
8cc6e90354a9
docs: tweak wording, punctuation for better readability
Greg Ward <greg@gerg.ca>
parents:
978
diff
changeset
|
380 in the earlier patch, and then the correction later on. |
978 | 381 |
382 You can avoid all this by amending the bad changeset and *evolving* | |
383 subsequent history. Here's how it works, assuming you have just | |
384 committed revision 13 and noticed the mistake in revision 11:: | |
385 | |
386 $ hg update 11 | |
387 [...fix mistake...] | |
388 $ hg amend | |
389 | |
390 At this point, revision 11 is *obsolete* and revisions 12 and 13—the | |
4618
803d32f4e498
docs: change `unstable` references to `orphan`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4616
diff
changeset
|
391 descendants of 11—are in a funny state: they are *orphan*. |
978 | 392 |
393 .. figure:: figures/figure-ug06.svg | |
394 | |
395 Figure 6: amending a changeset with descendants means the amended | |
396 changeset is obsolete but remains visible; its non-obsolete | |
4626
561e97db1cf7
docs: drop references to the old temporary commit that was created with amend
Matt Harbison <matt_harbison@yahoo.com>
parents:
4621
diff
changeset
|
397 descendants are *orphan*. |
978 | 398 |
2931 | 399 All non-obsolete descendants of an obsolete changeset are considered |
4618
803d32f4e498
docs: change `unstable` references to `orphan`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4616
diff
changeset
|
400 orphans. An interesting consequence of this is that revision 11 is |
2931 | 401 still visible, even though it is obsolete. Obsolete changesets with |
402 non-obsolete descendants are not hidden. | |
978 | 403 |
404 The fix is to *evolve* history:: | |
405 | |
406 $ hg evolve --all | |
407 | |
408 This is a separate step, not automatically part of ``hg amend``, | |
409 because there might be conflicts. If your amended changeset modifies a | |
410 file that one of its descendants also modified, Mercurial has to fire | |
411 up your merge tool to resolve the conflict. More importantly, you have | |
2931 | 412 to switch from "writing code" to "resolving conflicts". That can be an |
413 expensive context switch, so Mercurial lets you decide when to do it. | |
978 | 414 |
415 The end state, after ``evolve`` finishes, is that the original | |
416 revisions (11-13) are obsolete and hidden. Their successor revisions | |
4626
561e97db1cf7
docs: drop references to the old temporary commit that was created with amend
Matt Harbison <matt_harbison@yahoo.com>
parents:
4621
diff
changeset
|
417 (14-16) replace them. |
978 | 418 |
419 .. figure:: figures/figure-ug07.svg | |
420 | |
421 Figure 7: evolve your repository (``hg evolve --all``) to take care | |
4618
803d32f4e498
docs: change `unstable` references to `orphan`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4616
diff
changeset
|
422 of instability. Orphan changesets become obsolete, and are |
978 | 423 replaced by successors just like the amended changeset was. |
424 | |
425 Example 8: Prune an older changeset | |
426 =================================== | |
427 | |
428 Let's say you've just committed the following changesets:: | |
429 | |
430 $ hg commit -m 'useful work' # rev 18 | |
431 $ hg commit -m 'debug hack' # rev 19 | |
432 $ hg commit -m 'more work' # rev 20 | |
433 | |
434 You want to drop revision 19, but keep 18 and 20. No problem:: | |
435 | |
436 $ hg prune 19 | |
437 1 changesets pruned | |
4618
803d32f4e498
docs: change `unstable` references to `orphan`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4616
diff
changeset
|
438 1 new orphan changesets |
978 | 439 |
440 As above, this leaves your repository in a funny intermediate state: | |
441 revision 20 is the non-obsolete descendant of obsolete revision 19. | |
4618
803d32f4e498
docs: change `unstable` references to `orphan`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4616
diff
changeset
|
442 That is, revision 20 is an orphan. |
978 | 443 |
444 .. figure:: figures/figure-ug08.svg | |
445 | |
446 Figure 8: ``hg prune`` marks a changeset obsolete without creating | |
447 a successor. Just like with ``hg amend``, non-obsolete descendants | |
4618
803d32f4e498
docs: change `unstable` references to `orphan`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4616
diff
changeset
|
448 of the pruned changeset are now orphans. |
978 | 449 |
4618
803d32f4e498
docs: change `unstable` references to `orphan`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4616
diff
changeset
|
450 As before, the solution to orphan changesets is to evolve your |
978 | 451 repository:: |
452 | |
453 $ hg evolve --all | |
454 | |
455 This rebases revision 20 on top of 18 as the new revision 21, leaving | |
456 19 and 20 obsolete and hidden: | |
457 | |
458 .. figure:: figures/figure-ug09.svg | |
459 | |
460 Figure 9: once again, ``hg evolve --all`` takes care of instability. | |
461 | |
462 Example 9: Uncommit files from an older changeset (discard changes) | |
463 ======================================================================= | |
464 | |
465 As in example 5, let's say you accidentally commit some unrelated | |
466 changes together. Unlike example 5, you don't notice your mistake | |
467 immediately, but commit a new changeset on top of the bad one. :: | |
468 | |
469 $ echo 'this fixes bug 53' >> file1.c | |
470 $ echo 'debug hack' >> file2.c | |
471 $ hg commit -m 'fix bug 53' # rev 22 (oops) | |
472 $ echo 'and this handles bug 67' >> file1.c | |
473 $ hg commit -m 'fix bug 67' # rev 23 (fine) | |
474 | |
475 As with ``amend``, you need to travel back in time and repair revision | |
476 22, leaving your changes to ``file2.c`` back in the working | |
477 directory:: | |
478 | |
479 $ hg update 22 | |
480 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
481 $ hg uncommit file2.c | |
4618
803d32f4e498
docs: change `unstable` references to `orphan`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4616
diff
changeset
|
482 1 new orphan changesets |
978 | 483 $ hg status |
484 M file2.c | |
485 | |
4618
803d32f4e498
docs: change `unstable` references to `orphan`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4616
diff
changeset
|
486 Now your repository has orphan changesets, so you need to evolve it. |
2931 | 487 However, ``hg evolve`` requires a clean working directory to resolve merge |
978 | 488 conflicts, so you need to decide what to do with ``file2.c``. |
489 | |
490 In this case, the change to ``file2.c`` was a temporary debugging | |
491 hack, so we can discard it and immediately evolve the instability away:: | |
492 | |
493 $ hg revert file2.c | |
494 $ hg evolve --all | |
495 move:[23] fix bug 67 | |
496 atop:[24] fix bug 53 | |
497 | |
498 Figure 10 illustrates the whole process. | |
499 | |
500 .. figure:: figures/figure-ug10.svg | |
501 | |
502 Figure 10: ``hg uncommit`` of a changeset with descendants results | |
503 in instability *and* a dirty working directory, both of which must | |
504 be dealt with. | |
505 | |
506 | |
507 Example 10: Uncommit files to an older changeset (keep changes) | |
508 =================================================================== | |
509 | |
510 This is very similar to example 9. The difference that this time, our | |
511 change to ``file2.c`` is valuable enough to commit, making things a | |
512 bit more complicated. The setup is nearly identical:: | |
513 | |
514 $ echo 'fix a bug' >> file1.c | |
515 $ echo 'useful but unrelated' >> file2.c | |
516 $ hg commit -u dan -d '11 0' -m 'fix a bug' # rev 26 (oops) | |
517 $ echo 'new feature' >> file1.c | |
518 $ hg commit -u dan -d '12 0' -m 'new feature' # rev 27 (fine) | |
519 | |
520 As before, we update back to the flawed changeset (this time, | |
2931 | 521 revision 26) and use ``uncommit``, leaving uncommitted changes to |
978 | 522 ``file2.c`` in the working dir:: |
523 | |
524 $ hg update -q 26 | |
525 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
2931 | 526 $ hg uncommit -q file2.c # obsoletes rev 26, creates rev 28 |
4618
803d32f4e498
docs: change `unstable` references to `orphan`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4616
diff
changeset
|
527 1 new orphan changesets |
978 | 528 $ hg status |
529 M file2.c | |
530 | |
531 This time, let's save that useful change before evolving:: | |
532 | |
533 $ hg commit -m 'useful tweak' # rev 29 | |
534 | |
535 Figure 11 shows the story so far: ``uncommit`` obsoleted revision 26 | |
536 and created revision 28, the successor of 26. Then we committed | |
2931 | 537 revision 29, a child of 28. We still have to deal with the revision 27, |
4618
803d32f4e498
docs: change `unstable` references to `orphan`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4616
diff
changeset
|
538 which is an orphan changeset. |
978 | 539 |
540 .. figure:: figures/figure-ug11.svg | |
541 | |
542 Figure 11: Uncommitting a file and then committing that change | |
543 separately will soon result in a two-headed repository. | |
544 | |
545 This is where things get tricky. As usual when a repository has | |
4618
803d32f4e498
docs: change `unstable` references to `orphan`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4616
diff
changeset
|
546 orphan changesets, we want to evolve it:: |
978 | 547 |
548 $ hg evolve --all | |
549 | |
550 The problem is that ``hg evolve`` rebases revision 27 onto revision | |
551 28, creating 30 (the successor of 27). This is entirely logical: 27 | |
552 was the child of 26, and 26's successor is 28. So of course 27's | |
553 successor (30) should be the child of 26's successor (28). | |
554 Unfortunately, that leaves us with a two-headed repository: | |
555 | |
556 .. figure:: figures/figure-ug12.svg | |
557 | |
4618
803d32f4e498
docs: change `unstable` references to `orphan`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4616
diff
changeset
|
558 Figure 12: ``evolve`` takes care of orphan changesets; it does |
978 | 559 not solve all the world's problems. |
560 | |
561 As usual when faced with a two-headed repository, you can either merge | |
562 or rebase. It's up to you. | |
563 | |
564 | |
565 Example 11: Recover an obsolete changeset | |
566 ========================================= | |
567 | |
1270 | 568 Sometimes you might obsolete a changeset, and then change your mind. You'll |
569 probably start looking for an “unobsolete” command to restore a changeset | |
570 to normal state. For complicated implementation reasons, that command | |
571 doesn't exist. (If you have already pushed an obsolescence marker to | |
572 another repo, then Mercurial would need a way to revoke that remote | |
573 obsolesence marker. That's a hard problem.) | |
574 | |
575 Instead, ``evolve`` provides a ``touch`` command to resurrect an | |
576 obsolete changeset. An unexpected quirk: you almost certainly need to | |
577 use ``--hidden``, since obsolete changesets tend to be hidden, and you | |
578 can't reference a hidden changeset otherwise. Typical usage thus looks | |
579 like :: | |
580 | |
581 $ hg --hidden touch REV | |
582 | |
583 This creates a new, normal changeset which is the same as ``REV``—except | |
584 with a different changeset ID. The new changeset will have the same parent | |
585 as ``REV``, and will be a successor of ``REV``. | |
586 | |
587 The current implementation of ``hg touch`` is not ideal, and is likely to | |
588 change in the future. Consider the history in Figure 12, where revision 27 | |
589 is obsolete and the child of 26, also obsolete. If we ``hg touch 27``, that | |
2931 | 590 creates a new revision which is a non-obsolete child of 26—i.e., it is an |
4620
a05bfdf372fb
docs: change `divergent` references to `content-divergent`
Matt Harbison <matt_harbison@yahoo.com>
parents:
4618
diff
changeset
|
591 orphan. It's also *content-divergent*, another type of trouble that we'll learn |
1270 | 592 about in the `next section`_. |
593 | |
594 .. _`next section`: sharing.html |