Mercurial > hg-website
comparison text/learning_mercurial_in_workflows.txt @ 111:8b51ceb2d36b
learning in workflows: Added backout.
author | Arne Babenhauserheide <bab@draketo.de> |
---|---|
date | Wed, 22 Apr 2009 22:29:38 +0200 |
parents | 8c8c8aaaaad7 |
children | 8a603a9cbc04 |
comparison
equal
deleted
inserted
replaced
110:8c8c8aaaaad7 | 111:8b51ceb2d36b |
---|---|
20 | 20 |
21 * Smoothing workflows with extensions -> i.e. shelve before merging. | 21 * Smoothing workflows with extensions -> i.e. shelve before merging. |
22 | 22 |
23 --> | 23 --> |
24 | 24 |
25 = Basic workflows = | |
26 | |
25 == Sysadmin workflow == | 27 == Sysadmin workflow == |
26 | 28 |
27 === Use Case === | 29 === Use Case === |
28 | 30 |
29 The first workflow is also the easiest one: You're a sysadmin and you want to use Mercurial to be able to look back when you did which changes. | 31 The first workflow is also the easiest one: You're a sysadmin and you want to use Mercurial to be able to look back when you did which changes. |
30 | 32 |
31 This workflow only requires an installed Mercurial and write access to some file storage (you almost definitely have that :) ). It shows the basic technics for more complex workflows. | 33 This workflow only requires an installed Mercurial and write access to some file storage (you almost definitely have that :) ). It shows the basic technics for more complex workflows. |
34 | |
35 Note: The name doesn't mean that every sysadmin will only need this simple workflow. It was chosen in honor of a [mail]() which reminded us, that this simple usage is already a workflow in its own right. | |
32 | 36 |
33 === Workflow === | 37 === Workflow === |
34 | 38 |
35 ==== Initialize the project ==== | 39 ==== Initialize the project ==== |
36 | 40 |
66 commit the changes. | 70 commit the changes. |
67 | 71 |
68 $ hg commit | 72 $ hg commit |
69 | 73 |
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. | 74 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. |
75 | |
76 Note: You can also supply teh commit message directly via "hg commit -m 'MESSAGE'" | |
71 | 77 |
72 ==== Check your history ==== | 78 ==== Check your history ==== |
73 | 79 |
74 $ hg log | 80 $ hg log |
75 | 81 |
141 $ hg commit | 147 $ hg commit |
142 | 148 |
143 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. | 149 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. |
144 | 150 |
145 | 151 |
146 So now you can initialize repositories, save changes, | 152 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. |
147 | 153 |
148 == Seperate features == | 154 == Seperate features == |
149 | 155 |
150 === Use Case === | 156 === Use Case === |
151 | 157 |
161 $ cd ../project | 167 $ cd ../project |
162 $ hg pull ../feature1 | 168 $ hg pull ../feature1 |
163 | 169 |
164 Now you have the history of feature1 inside your project, but they aren't yet visible. Instead they are only stored inside the .hg directory inside the project. | 170 Now you have the history of feature1 inside your project, but they aren't yet visible. Instead they are only stored inside the .hg directory inside the project. |
165 | 171 |
166 From now on we'll use the name "repository" for a directory which has a .hg directory with Mercurial history. | 172 Note: From now on we'll use the name "repository" for a directory which has a .hg directory with Mercurial history. |
167 | 173 |
168 If you didn't do any changes in the project, while you were working on feature1, you can just update, but it is more likely that you'll have done some changes. In that case, it's time for merging. | 174 If you didn't do any changes in the project, while you were working on feature1, you can just update to tip ("hg update tip"), but it is more likely that you'll have done some other changes in between changes. In that case, it's time for merging. |
169 | 175 |
170 Merge feature1 into the project code: | 176 Merge feature1 into the project code: |
171 | 177 |
172 $ hg merge | 178 $ hg merge |
173 | 179 |
227 We assume that you want to export changeset 3 and 4: | 233 We assume that you want to export changeset 3 and 4: |
228 | 234 |
229 $ hg export 3 > change3.diff | 235 $ hg export 3 > change3.diff |
230 $ hg export 4 > change4.diff | 236 $ hg export 4 > change4.diff |
231 | 237 |
232 Now attach them to an email and your collegues can just run "import" in both to get your full changes, including your user account. | 238 Now attach them to an email and your collegues can just run "import" on both diffs to get your full changes, including your user information. |
233 | 239 |
234 To be careful, they first clone their repository to have an integration directory: | 240 To be careful, they first clone their repository to have an integration directory: |
235 | 241 |
236 $ hg clone project integration | 242 $ hg clone project integration |
237 $ cd integration | 243 $ cd integration |
238 $ hg import change3.diff | 244 $ hg import change3.diff |
239 $ hg import change4.diff | 245 $ hg import change4.diff |
240 | 246 |
241 That's it. They can now test your changes in feature clones. If they accept them, | 247 That's it. They can now test your changes in feature clones. If they accept them, they pull the changes into the main repository. |
242 they pull the changes into the main repository. | 248 |
249 $ cd ../project | |
250 $ hg pull ../integration | |
243 | 251 |
244 Note: The patchbomb extension automates the email-sending, but you don't need it for this workflow. | 252 Note: The patchbomb extension automates the email-sending, but you don't need it for this workflow. |
245 | 253 |
254 Note 2: You can also send around bundles, which are snippets of your actual history. Just create them via | |
255 $ hg bundle --base FIRST_REVISION_TO_BUNDLE changes.bundle | |
256 Others can then get your changes by simply pulling them, as if your bundle were an actual repository | |
257 $ hg pull path/to/changes.bundle | |
258 | |
246 ==== Using a shared repository ==== | 259 ==== Using a shared repository ==== |
247 | 260 |
248 Sending changes by mail might be the easiest way to reach people, but it creates additional workload: You have to send mails and then import the changes manually. Luckily there's an easier way which works quite well for smaller teams: The shared push repository. | 261 Sending changes by mail 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 send mails and then import the changes manually. Luckily there's an easier way which works quite well: The shared push repository. |
249 | 262 |
250 Till now we transferred all changes either via email or via pull, but there's yet another way: pushing. As the name suggests it's just the opposite of pulling: You push your changes into another repository. | 263 Till now we transferred all changes either via email or via pull, but there's yet another way: pushing. As the name suggests it's just the opposite of pulling: You push your changes into another repository. |
251 | 264 |
252 But to make use of it, we first need something we can push to. | 265 But to make use of it, we first need something we can push to. |
253 | 266 |
289 | 302 |
290 $ hg clone https://bitbucket.org/ArneBab/1w6/ 1w6 | 303 $ hg clone https://bitbucket.org/ArneBab/1w6/ 1w6 |
291 | 304 |
292 That local repository will automatically be configured to pull/push from/to the online repository, so new contributors can just use "hg push" and "hg pull" without an URL. | 305 That local repository will automatically be configured to pull/push from/to the online repository, so new contributors can just use "hg push" and "hg pull" without an URL. |
293 | 306 |
307 Note: To make this workflow more scaleable, each one of you can have his own BitBucket repository and you can simply pull from the others repositories. That way you can easily establish workflows in which certain people act as integrators and finally push checked code to a shared pull repository from which all others pull. | |
308 | |
309 == Summary == | |
310 | |
311 Now let's take a step back and look where we are. | |
312 | |
313 With the commands you already know, a bit reading of "hg help <command>" 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. | |
314 | |
315 First this is good, because it means, that you can now use most of the concepts which are used in more complex workflows. | |
316 | |
317 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. | |
318 | |
319 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: | |
320 | |
321 create a project | |
322 | |
323 $ hg init project | |
324 $ cd project | |
325 $ (add some files) | |
326 $ hg add | |
327 $ hg commit | |
328 (enter the commit message) | |
329 | |
330 do nonlinear development | |
331 | |
332 $ (do some changes) | |
333 $ hg commit | |
334 (enter the commit message) | |
335 $ hg update 0 | |
336 $ (do some changes) | |
337 $ hg commit | |
338 (enter the commit message) | |
339 $ hg merge | |
340 $ (optionally hg resolve) | |
341 $ hg commit | |
342 (enter the commit message) | |
343 | |
344 use feature clones | |
345 | |
346 $ cd .. | |
347 $ hg clone project feature1 | |
348 $ cd feature1 | |
349 $ (do some changes) | |
350 $ hg commit | |
351 (enter the commit message) | |
352 $ cd ../project | |
353 $ hg pull ../feature1 | |
354 | |
355 share your repository via the integrated webserver | |
356 | |
357 $ hg serve & | |
358 $ cd .. | |
359 $ hg clone http://127.0.0.1:8000 project-clone | |
360 | |
361 export changes to files | |
362 | |
363 $ cd project-clone | |
364 $ (do some changes) | |
365 $ hg commit | |
366 (enter the commit message) | |
367 $ hg export tip > ../changes.diff | |
368 | |
369 import changes from files | |
370 | |
371 $ cd ../project | |
372 $ hg import ../changes.diff | |
373 | |
374 pull changes from a served repository (hg serve still runs on project) | |
375 | |
376 $ cd ../feature1 | |
377 $ hg pull http://127.0.0.1:8000 | |
378 | |
379 Use shared repositories on BitBucket | |
380 | |
381 $ (setup bitbucket repo) | |
382 $ hg push https://bitbucket.org/USER/REPO | |
383 (enter name and password in the prompt) | |
384 $ hg pull https://bitbucket.org/USER/REPO | |
385 | |
386 | |
387 Let's move on towards useful features and a bit more advanced workflows. | |
388 | |
389 == Backing out bad revisions == | |
390 | |
391 === Use Case === | |
392 | |
393 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. | |
394 | |
395 To resolve that problem, Mercurial offers you the backout 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. | |
396 | |
397 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. | |
398 | |
399 === Workflow === | |
400 | |
401 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 backout of it. This creates a new change which reverses the bad change. After backing out, we merge that new change into the current code. | |
402 | |
403 $ hg backout 3 | |
404 $ hg merge | |
405 (potentially resolve conflicts) | |
406 $ hg commit | |
407 (enter commit message. For example: "merged backout") | |
408 | |
409 That's it. You reversed the bad change. | |
410 | |
411 == Collaborative feature development == | |
412 | |
413 -> branches | |
414 | |
415 == Tagging revisions == | |
416 | |
417 -> hg tag | |
418 | |
419 == Removing history == | |
420 | |
421 -> hg clone -r , hg export, hg import, ... | |
422 | |
423 | |
424 = More Complex Workflows = | |
425 | |
426 | |
427 | |
428 = Smoothing workflows with extensions = |