comparison hgscm/templates/workflow_guide.html @ 143:fc5a9f3e5479

Converted the workflow guide into html, added links and polished it.
author Arne Babenhauserheide <bab@draketo.de>
date Tue, 12 May 2009 06:20:17 +0200
parents text/learning_mercurial_in_workflows.txt@cf102ae37ad9
children 730b34064342
comparison
equal deleted inserted replaced
142:359a05e0b013 143:fc5a9f3e5479
1 {% extends "base.html" %}
2
3 {% load extras %}
4 {% block content %}
5
6 <div class="row">
7 <div class="col big">
8
9
10 <h1>Learning Mercurial in Workflows</h1>
11
12 <p>With Mercurial you can use a multitude of different workflows. This page shows some of them, including their use cases. It is intended to make it easy for Beginners of Version tracking to get going instantly and learn completely incrementally. It doesn't explain the concepts used, because there are already many other great resources doing that, for example <a title="Understanding Mercurial" href="http://www.selenic.com/mercurial/wiki/UnderstandingMercurial">the wiki</a> and <a title="Behind the Scenes" href="http://hgbook.red-bean.com/read/behind-the-scenes.html">the hgbook</a>.</p>
13
14 <p>If you want a more exhaustive tutorial with the basics, please have a look at the <a title="Mercurial Tutorial" href="http://www.selenic.com/mercurial/wiki/Tutorial">Tutorial in the Mercurial Wiki</a>. For a really detailed and very nice to read description of Mercurial, please have a look at <a title="Mercurial: The definitive Guide" href="http://hgbook.red-bean.com/">Mercurial: The definitive Guide</a>.</p>
15
16 <h2>Basic workflows</h2>
17
18 <h3>Log keeping</h3>
19
20 <h4>Use Case</h4>
21
22 The first workflow is also the easiest one: You want to use Mercurial to be able to look back when you did which changes.
23
24 This workflow only requires an installed Mercurial and write access to some file storage (you almost definitely have that :) ). It shows the basic techniques for more complex workflows.
25
26 <h4>Workflow</h4>
27
28 <h5>Prepare MercuriaL</h5>
29
30 As first step, you should teach Mercurial your name. For that you open the file ~/.hgrc with a text-editor and add the ui section (user interaction) with your username:
31
32 <pre>[ui]
33 username = Mr. Johnson <johnson@smith.com></pre>
34
35 <h5>Initialize the project</h5>
36
37 <pre>$ hg init project</pre>
38
39 <h5>Add files and track them</h5>
40
41 <pre>$ cd project
42 $ (add files)
43 $ hg add </pre>
44
45 Note: You can also go into an existing directory with files and init the repository there.
46
47 <pre>$ cd project
48 $ hg init</pre>
49
50 Alternatively you can add only specific files instead of all files in the directory. Mercurial will then track only these files and won't know about the others. The following tells mercurial to track all files whose names begin with "file0" as well as file10, file11 and file12.
51
52 <pre>$ hg add file0* file10 file11 file12</pre>
53
54 <h5>Save changes</h5>
55
56 <pre>$ (do some changes)</pre>
57
58 see which files changed, which have been added or removed, and which aren't tracked yet.
59
60 <pre>$ hg status</pre>
61
62 see the exact changes.
63
64 <pre>$ hg diff</pre>
65
66 commit the changes.
67
68 <pre>$ hg commit</pre>
69
70 now an editor pops up and asks you for a commit message. Upon saving and closing the editor, your changes have been stored by Mercurial.
71
72 Note: You can also supply the commit message directly via <hg>hg commit -m 'MESSAGE'</hg>
73
74 <h5>Check your history</h5>
75
76 <pre>$ hg log</pre>
77
78 This prints a list of changesets along with their date, the user who committed them (you) and their commit message.
79
80 To see a certain diff, you can use the <hg>-p</hg> switch (--patch)
81
82 <pre>$ hg log -p -r 3</pre>
83
84 <h3>Lone developer with linear history</h3>
85
86 <h4>Use case</h4>
87
88 The second workflow is still very easy: You're a lone developer and you want to use Mercurial to keep track of your own changes.
89
90 It works just like the sysadmin workflow, with the difference that you go back to earlied changes at times.
91
92 To start a new project, you initialize a repository, add your files and commit whenever you finished a part of your work.
93
94 Also you check your history from time to time, so see how you progressed.
95
96 <h4>Workflow</h4>
97
98 <h5>Basics from log keeping</h5>
99
100 Init your project, add files, see changes and commit them.
101
102 <pre>$ hg init project
103 $ cd project
104 $ (add files)
105 $ hg add # tell Mercurial to track all files
106 $ (do some changes)
107 $ hg diff # see changes
108 $ hg commit # save changes
109 $ hg log # see history</pre>
110
111 <h5>Seeing an earlier revision</h5>
112
113 Different from the sysadmin workflow, you'll want to go back in history at times and undo some changes, for example because it introduced a bug.
114
115 To look at a previous version of your code, you can use update. Let's assume that you want to see revision 3.
116
117 <pre>$ hg update 3</pre>
118
119 Now your code is back at revision 3, the fourth commit (Mercurial starts counting at 0).
120 To check if you're really at that revision, you can use <hg>identify -n</hg>.
121
122 <pre>$ hg identify -n</pre>
123
124 Note: <hg>identify</hg> without options gives you the short form of a unique revision ID. That ID is what Mercurial uses internally. If you tell someone about the version you updated to, you should use that ID, since the numbers can be different for other people. If you want to know the reasons behind that, please read up Mercurials [basic concepts](). When you're at the most recent revision, <hg>hg identify -n</hg> will return "-1".
125
126 To update to the most recent revision, you can use "tip" as revision name.
127
128 <pre>$ hg update tip</pre>
129
130 Note: If at any place any command complains, your best bet is to read what it tells you and follow that advice.
131
132 Note: Instead of <hg>hg update</hg> you can also use the shorthand <hg>hg up</hg>. Similarly you can abbreviate <hg>hg commit</hg> to <hg>hg ci</hg>.
133
134 Note: To get a revision devoid of files, just <hg>update</hg> to "null" via <hg>hg update null</hg>. That's the revision before any files were added.
135
136 <h5>Fixing errors in earlier revisions</h5>
137
138 When you find a bug in some earlier revision you have two options: either you can fix it in the current code, or you can go back in history and fix the code exactly where you did it, which creates a cleaner history.
139
140 To do it the cleaner way, you first update to the old revision, fix the bug and commit it. Afterwards you merge this revision and commit the merge. Don't worry, though: Merging in mercurial is fast and painless, as you'll see in an instant.
141
142 Let's assume the bug was introduced in revision 3.
143
144 <pre>$ hg update 3
145 $ (fix the bug)
146 $ hg commit</pre>
147
148 Now the fix is already stored in history. We just need to merge it with the current version of your code.
149
150 <pre>$ hg merge</pre>
151
152 If there are conflicts use <hg>hg resolve</hg> - that's also what merge tells you to do in case of conflicts.
153
154 First list the files with conflicts:
155
156 <pre>$ hg resolve --list</pre>
157
158 Then resolve them one by one. <hg>resolve</hg> attempts the merge again:
159
160 <pre>$ hg resolve conflicting_file
161 (fix it by hand, if necessary)</pre>
162
163 Mark the fixed file as resolved:
164
165 <pre>$ hg resolve --mark conflicting_file</pre>
166
167 Commit the merge, as soon as you resolved all conflicts. This step is also necessary if there were no conflicts!
168
169 <pre>$ hg commit</pre>
170
171 At this point, your fix is merged with all your other work, and you can just go on coding. Additionally the history shows clearly where you fixed the bug, so you'll always be able to check where the bug was.
172
173 Note: Most merges will just work. You only need <hg>resolve</hg>, when <hg>merge</hg> complains.
174
175 So now you can initialize repositories, save changes, update to previous changes and develop in a nonlinear history by committing in earlier changesets and merging the changes into the current code.
176
177 <h3>Seperate features</h3>
178
179 <h4>Use Case</h4>
180
181 At times you'll be working on several features in parallel. If you want to avoid mixing incomplete code versions, you can create clones of your local repository and work on each feature in its own code directory.
182
183 After finishing your feature you then <hg>pull</hg> it back into your main directory and <hg>merge</hg> the changes.
184
185 <h4>Workflow</h4>
186
187 First create the feature clone and do some changes
188
189 <pre>$ hg clone project feature1
190 $ cd feature1
191 $ (do some changes and commits)</pre>
192
193 Now check what will come in when you <hg>pull</hg> from feature1, just like you can use <hg>diff</hg> before committing. The respective command for pulling is <hg>incoming</hg>
194
195 <pre>$ cd ../project
196 $ hg incoming ../feature1</pre>
197
198 Note: If you want to see the diffs, you can use <hg>hg incoming --patch</hg> just as you can do with <hg>hg log --patch</hg> for the changes in the repository.
199
200 If you like the changes, you pull them into the project
201
202 <pre>$ hg pull ../feature1</pre>
203
204 Now you have the history of feature1 inside your project, but the changes aren't yet visible. Instead they are only stored inside a ".hg" directory of the project (<a title="Behind the Scenes" href="http://hgbook.red-bean.com/read/behind-the-scenes.html">more information on the store</a>).
205
206 Note: From now on we'll use the name "repository" for a directory which has a .hg directory with Mercurial history.
207
208 If you didn't do any changes in the project, while you were working on feature1, you can just update to tip (<hg>hg update tip</hg>), but it is more likely that you'll have done some other changes in between changes. In that case, it's time for merging.
209
210 Merge feature1 into the project code:
211
212 <pre>$ hg merge</pre>
213
214 If there are conflicts use <hg>hg resolve</hg> - that's also what merge tells you to do in case of conflicts. After you <hg>merge</hg>, you have to <hg>commit</hg> explicitely to make your <hg>merge</hg> final
215
216 <pre>$ hg commit
217 (enter commit message, for example "merged feature1")</pre>
218
219 You can create an arbitrary number of clones and also carry them around on USB sticks. Also you can use them to synchronize your files at home and at work, or between your desktop and your laptop.
220
221 Note: You also have to commit after a merge when there are no conflicts, because merging creates new history and you might want to attach a specific message to the merge (like "merge feature1").
222
223 <h3>Sharing changes</h3>
224
225 <h4>Use Case</h4>
226
227 Now we go one step further: You are no longer alone, and you want to share your changes with others and include their changes.
228
229 The basic requirement for that is that you have to be able to see the changes of others.
230
231 Mercurial allows you to do that very easily by including a simple webserver from which you can <hg>pull</hg> changes just as you can pull changes from local clones.
232
233 Note: There are a few other ways to share changes, though. Instead of using the builtin webserver, you can also send the changes by email or setup a shared repository, to where you <hg>push</hg> changes instead of pulling them. We'll cover one of those later.
234
235 <h4>Workflow</h4>
236
237 <h5>Using the builtin webserver</h5>
238
239 This is the easiest way to quickly share changes.
240
241 First the one who wants to share his changes creates the webserver
242
243 <pre>$ hg serve</pre>
244
245 Now all others can point their browsers to his IP address (for example 192.168.178.100) at port 8000. They will then see all his history there and can sdecide if they want to pull his changes.
246
247 <pre>$ firefox http://192.168.178.100:8000</pre>
248
249 If they decide to include the changes, they just pull from the same URL
250
251 <pre>$ hg pull http://192.168.178.100:8000</pre>
252
253 At this point you all can work as if you had pulled from a local repository. All the data is now in your individual repositories and you can merge the changes and work with them without needing any connection to the served repository.
254
255 <h5>Sending changes by email</h5>
256
257 Often you won't have direct access to the repository of someone else, be it because he's behind a restrictive firewall, or because you live in different timezones. You might also want to keep your changes confidential and prefer internal email (if you want additional protection, you can also encrypt the emails, for example with <a href="http://gnupg.org" title="GnuPG">GnuPG</a>).
258
259 In that case, you can easily export your changes as patches and send them by email.
260
261 Another reason to send them by email can be that your policy requires manual review of the changes when the other developers are used to reading diffs in emails. I'm sure you can think of more reasons.
262
263 Sending the changes via email is pretty straightforward with Mercurial. You just <hg>export</hg> your changes and attach (or copy paste) it in your email. Your collegues can then just <hg>import</hg> them.
264
265 First check which changes you want to export
266
267 <pre>$ cd project
268 $ hg log</pre>
269
270 We assume that you want to export changeset 3 and 4:
271
272 <pre>$ hg export 3 > change3.diff
273 $ hg export 4 > change4.diff</pre>
274
275 Now attach them to an email and your collegues can just run <hg>import</hg> on both diffs to get your full changes, including your user information.
276
277 To be careful, they first <hg>clone</hg> their repository to have an integration directory as sandbox
278
279 <pre>$ hg clone project integration
280 $ cd integration
281 $ hg import change3.diff
282 $ hg import change4.diff</pre>
283
284 That's it. They can now test your changes in feature clones. If they accept them, they <hg>pull</hg> the changes into the main repository
285
286 <pre>$ cd ../project
287 $ hg pull ../integration</pre>
288
289 Note: The <em>patchbomb</em> extension automates the email-sending, but you don't need it for this workflow.
290
291 Note 2: You can also send around bundles, which are snippets of your actual history. Just create them via
292 <pre>$ hg bundle --base FIRST_REVISION_TO_BUNDLE changes.bundle</pre>
293 Others can then get your changes by simply pulling them, as if your bundle were an actual repository
294 <pre>$ hg pull path/to/changes.bundle</pre>
295
296 <h5>Using a shared repository</h5>
297
298 Sending changes by email might be the easiest way to reach people when you aren't yet part of the regular development team, but it creates additional workload: You have to <hg>bundle</hg> the changes, send mails and then <hg>import</hg> the bundles manually. Luckily there's an easier way which works quite well: The shared push repository.
299
300 Till now we transferred all changes either via email or via <hg>pull</hg>. Now we use another otion: pushing. As the name suggests it's just the opposite of pulling: You <hg>push</hg> your changes into another repository.
301
302 But to make use of it, we first need something we can push to.
303
304 By default <hg>hg serve</hg> doesn't allow pushing, since that would be a major security hole. You can allow pushing in the server, but that's no solution when you live in different timezones, so we'll go with another approach here: Using a shared repository, either on an existing shared server or on a service like <a title="BitBucket" href="http://bitbucket.org">BitBucket</a>. Doing so has a bit higher starting cost and takes a bit longer to explain, but it's well worth the effort spent.
305
306 If you want to use an existing shared server, you can use <hg>serve</hg> there and <a title="How to allow pushing for hg serve" href="http://www.selenic.com/mercurial/wiki/HgWebDirStepByStep#head-746ca383e3a62df34279ec2fca888113497da022">allow pushing</a>. Also there are some other nice ways to <a title="Multiple Committers" href="http://www.selenic.com/mercurial/wiki/MultipleCommitters">allow pushing to a Mercurial repository</a>, including simple <a title="Setting up a shared Mercurial repository using SSH" href="http://www.selenic.com/mercurial/wiki/SharedSSH">access via SSH</a>.
307
308 Otherwise you first need to setup a BitBucket Account. Just signup at <a title="BitBucket" href="http://bitbucket.org">BitBucket</a>. After signing up (and login) hover your mouse over "Repositories". There click the item at the bottom of the opening dialog which say "Create new".
309
310 Give it a name and a description. If you want to keep it hidden from the public, select "private".
311
312 <pre>$ firefox http://bitbucket.org</pre>
313
314 Now your repository is created and you see instructions for <hg>push</hg>ing to it. for that you'll use a command similar to the following (just with a different URL):
315
316 <pre>$ hg push https://bitbucket.org/ArneBab/hello/</pre>
317
318 (Replace the URL with the URL of your created repository. If your username is "Foo" and your repository is named "bar", the URL will be https://bitbucket.org/Foo/bar/)
319
320 Mercurial will ask for your BitBucket password, then <hg>push</hg> your code.
321
322 VoilĂ , your code is online.
323
324 Note: You can also <a title="use SSH for pushing to BitBucket" href="http://bitbucket.org/help/UsingSSH">use SSH for pushing to BitBucket</a>.
325
326 Now it's time to tell all your collegues to sign up at BitBucket, too.
327
328 After that you can click the "Admin" tab of your created repository and add the usernames of your collegues on the right side under "Permission: Writers". Now they are allowed to <hg>push</hg> code to the repository.
329
330 (If you chose to make the repository private, you'll need to add them to "Permission: Readers", too)
331
332 If one of you now wants to publish changes, he'll simply <hg>push</hg> them to the repository, and all others get them by <hg>pull</hg>ing.
333
334 Publish your changes:
335
336 <pre>$ hg push https://bitbucket.org/ArneBab/hello/</pre>
337
338 Pull others changes into your local repository:
339
340 <pre>$ hg pull https://bitbucket.org/ArneBab/hello/</pre>
341
342 People who join you in development can also just <hg>clone</hg> this repository, as if one of you were using <hg>hg serve</hg>:
343
344 <pre>$ hg clone https://bitbucket.org/ArneBab/hello/ hello</pre>
345
346 That local repository will automatically be configured to pull/push from/to the online repository, so new contributors can just use <hg>hg push</hg> and <hg>hg pull</hg> without an URL.
347
348 Note: To make this workflow more scaleable, each one of you can have his own BitBucket repository and you can simply <hg>pull</hg> from the others repositories. That way you can easily establish workflows in which certain people act as integrators and finally <hg>push</hg> checked code to a shared pull repository from which all others pull.
349
350 Note: You can also use this workflow with a shared server instead of BitBucket, either via SSH or via a shared directory. An example for an SSH URL with Mercurial is be ssh://hg@bitbucket.org/ArneBab/hello (for a shared server you'd replace the "hg" in the given URL with your username). When using a shared directory you just push as if the repository in the shared directory were on your local drive.
351
352 <h3>Summary</h3>
353
354 Now let's take a step back and look where we are.
355
356 With the commands you already know, a bit reading of <hg>hg help &lt;command&gt;</hg> and some evil script-fu you can already do almost everything you'll ever need to do when working with source code history. So from now on almost everything is convenience, and that's a good thing.
357
358 First this is good, because it means, that you can now use most of the concepts which are utilized in more complex workflows.
359
360 Second it aids you, because convenience lets you focus on your task instead of focussing on your tool. It helps you concentrate on the coding itself. Still you can always go back to the basics, if you want to.
361
362 A short summary of what you can do which can also act as a short check, if you still remember the meaning of the commands:
363
364 <h4>create a project</h4>
365
366 <pre>$ hg init project
367 $ cd project
368 $ (add some files)
369 $ hg add
370 $ hg commit
371 (enter the commit message)</pre>
372
373 <h4>do nonlinear development</h4>
374
375 <pre>$ (do some changes)
376 $ hg commit
377 (enter the commit message)
378 $ hg update 0
379 $ (do some changes)
380 $ hg commit
381 (enter the commit message)
382 $ hg merge
383 $ (optionally hg resolve)
384 $ hg commit
385 (enter the commit message)</pre>
386
387 <h4>use feature clones</h4>
388
389 <pre>$ cd ..
390 $ hg clone project feature1
391 $ cd feature1
392 $ (do some changes)
393 $ hg commit
394 (enter the commit message)
395 $ cd ../project
396 $ hg pull ../feature1</pre>
397
398 <h4>share your repository via the integrated webserver</h4>
399
400 <pre>$ hg serve &amp;
401 $ cd ..
402 $ hg clone http://127.0.0.1:8000 project-clone</pre>
403
404 <h4>export changes to files</h4>
405
406 <pre>$ cd project-clone
407 $ (do some changes)
408 $ hg commit
409 (enter the commit message)
410 $ hg export tip > ../changes.diff</pre>
411
412 <h4>import changes from files</h4>
413
414 <pre>$ cd ../project
415 $ hg import ../changes.diff</pre>
416
417 <h4>pull changes from a served repository (hg serve still runs on project)</h4>
418
419 <pre>$ cd ../feature1
420 $ hg pull http://127.0.0.1:8000</pre>
421
422 <h4>Use shared repositories on BitBucket</h4>
423
424 <pre>$ (setup bitbucket repo)
425 $ hg push https://bitbucket.org/USER/REPO
426 (enter name and password in the prompt)
427 $ hg pull https://bitbucket.org/USER/REPO</pre>
428
429
430 Let's move on towards useful features and a bit more advanced workflows.
431
432 <h3>Backing out bad revisions</h3>
433
434 <h4>Use Case</h4>
435
436 When you routinely pull code from others, it can happen that you overlook some bad change. As soon as others pull that change from you, you have little chance to get completely rid of it.
437
438 To resolve that problem, Mercurial offers you the <hg>backout</hg> command. Backing out a change means, that you tell Mercurial to create a commit which reverses the bad change. That way you don't get rid of the bad code in history, but you can remove it from new revisions.
439
440 Note: The basic commands don't directly rewrite history. If you want to do that, you need to activate some of the extensions which are shipped with mercurial. We'll come to that later on.
441
442 <h4>Workflow</h4>
443
444 Let's assume the bad change was revision 3, and we already have one more revision in our repository. To remove the bad code, we just <hg>backout</hg> of it. This creates a new change which reverses the bad change. After backing out, we merge that new change into the current code.
445
446 <pre>$ hg backout 3
447 $ hg merge
448 (potentially resolve conflicts)
449 $ hg commit
450 (enter commit message. For example: "merged backout")</pre>
451
452 That's it. You reversed the bad change. It's still recorded that it was once there (following the principle "don't rewrite history, if it's not really necessary"), but it doesn't affect future code anymore.
453
454 <h3>Collaborative feature development</h3>
455
456 Now that we can share changes and reverse them if necessary, we go one step further: Using Mercurial to help in coordinating the coding.
457
458 The first part is an easy way to develop features together, without requiring every developer to keep track of several feature clones.
459
460 <h4>Use Case</h4>
461
462 When you want to split your development into several features, you need to keep track of who works on which feature and where to get which changes.
463
464 Mercurial makes this easy for you by providing named branches. They are a part of the main repository, so they are available to everyone involved. At the same time, changes committed on a certain branch don't get mixed with the changes in the default branch, so features are kept separate, until they get merged into the default branch.
465
466 Note: Cloning a repository always puts you onto the default branch at first.
467
468 <h4>Workflow</h4>
469
470 When someone in your group wants to start coding on a feature without disturbing the others, he can create a named branch and commit there. When someone else wants to join in, he just updates to the branch and commits away. As soon as the feature is finished, someone merges the named branch into the default branch.
471
472 <h5>Working in a named branch</h5>
473
474 Create the branch:
475
476 <pre>$ hg branch feature1
477 (do some changes)
478 $ hg commit
479 (write commit message)</pre>
480
481 Update into the branch and work in it:
482
483 <pre>$ hg update feature1
484 (do some changes)
485 $ hg commit
486 (write commit message)</pre>
487
488 Now you can <hg>commit</hg>, <hg>pull</hg>, <hg>push</hg> and <hg>merge</hg> (and anything else) as if you were working in a separate repository. If the history of the named branch is linear and you call "hg merge", Mercurial asks you to specify an explicit revision, since the branch in which you work doesn't have anything to merge.
489
490 <h5>Merge the named branch</h5>
491
492 When you finished the feature, you <hg>merge</hg> the branch back into the default branch.
493
494 <pre>$ hg update default
495 $ hg merge feature1
496 $ hg commit
497 (write commit message)</pre>
498
499 And that's it. Now you can easily keep features separate without unnecessary bookkeeping.
500
501 Note: Named branches stay in history as permanent record after you finished your work. If you don't like having that record in your history, please have a look at some of the advanced <a title="Mercurial Workflows" href="http://www.selenic.com/mercurial/wiki/Workflows">workflows</a>.
502
503 <h3>Marking revisions: tag and sign</h3>
504
505 <h4>Use Case</h4>
506
507 Since you can now code separate features more easily, you might want to mark certain revisions as fit for consumption (or similar). For example you might want to mark releases, or just mark off revisions as reviewed.
508
509 For this Mercurial offers tags. Tags add a name to a revision and are part of the history. You can tag a change years after it was committed. The tag includes the information when it was added, and tags can be pulled, pushed and merged just like any other committed change.
510
511 Note: A tag must not contain the char ":", since that char is used for specifying multiple reivions - see "hg help revisions".
512
513 Note: To securely mark a revision, you can use the <a title="Using GnuPG to securely sign revisions in Mercurial" href="http://www.selenic.com/mercurial/wiki/GpgExtension">gpg extension</a> to sign the tag.
514
515 <h4>Workflow</h4>
516
517 Let's assume you want to give revision 3 the name "v0.1".
518
519 Add the tag:
520
521 <pre>$ hg tag -r 3 v0.1</pre>
522
523 See all tags:
524
525 <pre>$ hg tags</pre>
526
527 When you look at the log you'll now see a line in changeset 3 which marks the Tag. If someone wants to <hg>update</hg> to the tagged revision, he can just use the name of your tag:
528
529 <pre>$ hg update v0.1</pre>
530
531 Now he'll be at the tagged revision and can work from there.
532
533
534 <h3>Removing history</h3>
535
536 <h4>Use Case</h4>
537
538 At times you will have changes in your repository, which you really don't want in it.
539
540 There are many advanced options for removing these, and most of them use great extensions (<a title="Mercurial Queues Extension" href="http://www.selenic.com/mercurial/wiki/MqExtension">Mercurial Queues</a> is the most often used one), but in this basic guide, we'll solve the problem with just the commands we already learned. But we'll use an option to clone which we didn't yet use.
541
542 This workflow becomes inconvenient when you need to remove changes, which are buried below many new changes. If you spot the bad changes early enough, you can get rid of them without too much effort, though.
543
544 <h4>Workflow</h4>
545
546 Let's assume you want to get rid of revision 2 and the highest revision is 3.
547
548 The first step is to use the "--rev" option to <hg>clone</hg>: Create a clone which only contains the changes up to the specified revision. Since you want to keep revision 1, you only clone up to that.
549
550 $ hg clone -r 1 project stripped
551
552 Now you can <hg>export</hg> the change 3 from the original repository (project) and <hg>import</hg> it into the stripped one.
553
554 <pre>$ cd project
555 $ hg export 3 > ../changes.diff
556 $ cd ../stripped
557 $ hg import ../changes.diff</pre>
558
559 If a part of the changes couldn't be applied, you'll see that part in *.rej files. If you have *.rej files, you'll have to include or discard changes by hand.
560
561 <pre>$ cat *.rej
562 (apply changes by hand)
563 $ hg commit
564 (write commit message)</pre>
565
566 That's it. <hg>hg export</hg> also includes the commit message, date, committer and similar metadata, so you are already done.
567
568 Note: removing history will change the revision IDs of revisions after the removed one, and if you pull from someone else who still has the revision you removed, you will pull the removed parts again. That's why rewriting history should most times only be done for changes which you didn't yet publicise.
569
570 <h3>Summary</h3>
571
572 So now you can work with Mercurial in private, and also share your changes in a multitude of ways.
573
574 Additionally you can also remove bad changes, either by creating a change in the repository which reverses the original change, or by really rewriting history, so it looks like the change never occured.
575
576 And you can separate the work on features in a single repository by using named branches and add tags to revisions which are visible markers for others and can be used to update to the tagged revisions.
577
578 With this we can conclude our practical guide.
579
580 <h2>More Complex Workflows</h2>
581
582 If you now want to check some more complex workflows, please have a look at the general <a title="Mercurial Workflows" href="http://selenic.com/mercurial/wiki/Workflows">workflows wikipage</a>.
583
584 To deepen your understanding, you should also check the <a title="Overview of the basic concepts of Mercurial" href="quick_start_concepts">basic concept overview</a>.
585
586 Have fun with Mercurial!
587
588
589
590 <div class="col">
591 {% download_button %}
592 {% mercurial_tricks %}
593 </div>
594 </div>
595
596 </div>
597
598 {% endblock %}