comparison text/workflows.txt @ 99:71ff3b94b20d

Added workflows sysadmin, lone developer and seperate features.
author Arne Babenhauserheide <bab@draketo.de>
date Wed, 22 Apr 2009 12:05:33 +0200
parents 991719e0dbf5
children 6e29cdea7b3a
comparison
equal deleted inserted replaced
98:ee091902dd43 99:71ff3b94b20d
2 2
3 With Mercurial you can use a multitude of different workflows. This page shows some of them, including their use cases. 3 With Mercurial you can use a multitude of different workflows. This page shows some of them, including their use cases.
4 4
5 It is intended to make it easier for you to create your own workflow. 5 It is intended to make it easier for you to create your own workflow.
6 6
7 To write this page we gathered [real life workflows](wiki - workflows), so every workflow in here has proven itself in real life usage. We begin with basic workflows and then go on to more complex examples.
8
9 <!--Structure:
10 * For whom? -> Why?
11 * What do you need? -> Resources + extensions
12 * Single Developer workflow
13 * Sharing changes. -->
14
15 <!-- Plan
16
17 * Simple workflows without extensions
18
19 * Complex Workflows, including collaborative patch development and similar.
20
21 * Smoothing workflows with extensions -> i.e. shelve before merging.
22
23 -->
24
25 == Sysadmin workflow ==
26
27 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.
28
29 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.
30
31 === Workflow ===
32
33 ==== Initialize the project ====
34
35 <code>$ hg init project</code>
36
37 ==== Add files and track them ====
38
39 <code>$ cd project
40 $ (add files)
41 $ hg add </code>
42
43 Note: You can also go into an existing directory with files and init the repository there.
44
45 $ cd project
46 $ hg init
47
48 You can also just add 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 beginning with "file0" as well as file10, file11 and file12.
49
50 $ hg add file0* file10 file11 file12
51
52 ==== Save changes ====
53
54 $ (do some changes)
55
56 see which files changed, which have been added or removed, and which aren't tracked yet.
57
58 $ hg status
59
60 see the exact changes.
61
62 $ hg diff
63
64 commit the changes.
65
66 $ hg commit
67
68 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.
69
70 ==== Check your history ====
71
72 $ hg log
73
74 This prints a list of changesets along with their data, the user who committed them (you) and their commit message.
75
76 == Lone developer with linear history ==
77
78 === Use case ===
79
80 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.
81
82 It works just like the sysadmin workflow, with the difference that you go back to earlied changes at times.
83
84 To start a new project, you initialize a repository, add your files and commit whenever you finished a part of your work (atomic commits).
85
86 Also you check your history from time to time, so see how you progressed.
87
88 === Workflow ===
89
90 ==== Basics from sysadmin ====
91
92 Init your project, add files, see changes and commit them.
93
94 <code>$ hg init project
95 $ cd project
96 $ (add files)
97 $ hg add # tell Mercurial to track all files
98 $ (do some changes)
99 $ hg diff # see changes
100 $ hg commit # save changes
101 $ hg log # see history
102
103 ==== Seeing an earlier revision ====
104
105 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.
106
107 To look at a previous version of your code, you can use update. Let's assume that you want to see revision 3.
108
109 $ hg update 3
110
111 Now your code is back at revision 3, the fourth commit (Mercurial starts couting at 0).
112
113 To update to the most recent revision, you can use "tip" as revision name.
114
115 $ hg update tip
116
117 Note: If at any place any command complains, your best bet is to read what it tells you and follow that advice.
118
119 Note: Instead of "hg update" you can also use the shorthand "hg up". Similarly you can abbreviate "hg commit" to "hg ci".
120
121 ==== Fixing errors in earlier revisions ====
122
123 When you find a bug in some earlier revision you have two options: eaither you can fix it in the current code, or you can go back in history and fix the code exactly where you did it.
124
125 To do so, 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.
126
127 Let's assume the bug was introduced in revision 3.
128
129 $ hg update 3
130 $ (fix the bug)
131 $ hg commit
132
133 Now the fix is already stored in history. We just need to merge it with the current version of your code.
134
135 $ hg merge
136
137 If there are conflicts use "hg resolve" - that's also what merge tells you to do in case of conflicts.
138
139 $ hg commit
140
141 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.
142
143
144 So now you can initialize repositories, save changes,
145
146 == Seperate features ==
147
148 === Use Case ===
149
150 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.
151
152 After finishing your feature you then "pull" it back into your main directory and "merge" the changes.
153
154 === Workflow ===
155
156 $ hg clone project feature1
157 $ cd feature1
158 $ (do some changes and commits)
159 $ cd ../project
160 $ hg pull ../feature1
161
162 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.
163
164 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.
165
166 Merge feature1 into the project code:
167
168 $ hg merge
169
170 If there are conflicts use "hg resolve" - that's also what merge tells you to do in case of conflicts.
171
172 $ hg commit -m "merged feature1"
173
174 You can create an arbitrary number of clones and also carry them around on USB sticks, so you an also synchronize your work at home and at work.
175