Autogenerated HTML docs for 026351a03507dc3a2e89e068c01234dc55914df2
[git.git] / cvs-migration.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"\r
2     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\r
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">\r
4 <head>\r
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\r
6 <meta name="generator" content="AsciiDoc 7.0.1" />\r
7 <style type="text/css">\r
8 /* Debug borders */\r
9 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {\r
10 /*\r
11   border: 1px solid red;\r
12 */\r
13 }\r
14 \r
15 body {\r
16   margin: 1em 5% 1em 5%;\r
17 }\r
18 \r
19 a { color: blue; }\r
20 a:visited { color: fuchsia; }\r
21 \r
22 em {\r
23   font-style: italic;\r
24 }\r
25 \r
26 strong {\r
27   font-weight: bold;\r
28 }\r
29 \r
30 tt {\r
31   color: navy;\r
32 }\r
33 \r
34 h1, h2, h3, h4, h5, h6 {\r
35   color: #527bbd;\r
36   font-family: sans-serif;\r
37   margin-top: 1.2em;\r
38   margin-bottom: 0.5em;\r
39   line-height: 1.3;\r
40 }\r
41 \r
42 h1 {\r
43   border-bottom: 2px solid silver;\r
44 }\r
45 h2 {\r
46   border-bottom: 2px solid silver;\r
47   padding-top: 0.5em;\r
48 }\r
49 \r
50 div.sectionbody {\r
51   font-family: serif;\r
52   margin-left: 0;\r
53 }\r
54 \r
55 hr {\r
56   border: 1px solid silver;\r
57 }\r
58 \r
59 p {\r
60   margin-top: 0.5em;\r
61   margin-bottom: 0.5em;\r
62 }\r
63 \r
64 pre {\r
65   padding: 0;\r
66   margin: 0;\r
67 }\r
68 \r
69 span#author {\r
70   color: #527bbd;\r
71   font-family: sans-serif;\r
72   font-weight: bold;\r
73   font-size: 1.2em;\r
74 }\r
75 span#email {\r
76 }\r
77 span#revision {\r
78   font-family: sans-serif;\r
79 }\r
80 \r
81 div#footer {\r
82   font-family: sans-serif;\r
83   font-size: small;\r
84   border-top: 2px solid silver;\r
85   padding-top: 0.5em;\r
86   margin-top: 4.0em;\r
87 }\r
88 div#footer-text {\r
89   float: left;\r
90   padding-bottom: 0.5em;\r
91 }\r
92 div#footer-badges {\r
93   float: right;\r
94   padding-bottom: 0.5em;\r
95 }\r
96 \r
97 div#preamble,\r
98 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,\r
99 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,\r
100 div.admonitionblock {\r
101   margin-right: 10%;\r
102   margin-top: 1.5em;\r
103   margin-bottom: 1.5em;\r
104 }\r
105 div.admonitionblock {\r
106   margin-top: 2.5em;\r
107   margin-bottom: 2.5em;\r
108 }\r
109 \r
110 div.content { /* Block element content. */\r
111   padding: 0;\r
112 }\r
113 \r
114 /* Block element titles. */\r
115 div.title, caption.title {\r
116   font-family: sans-serif;\r
117   font-weight: bold;\r
118   text-align: left;\r
119   margin-top: 1.0em;\r
120   margin-bottom: 0.5em;\r
121 }\r
122 div.title + * {\r
123   margin-top: 0;\r
124 }\r
125 \r
126 td div.title:first-child {\r
127   margin-top: 0.0em;\r
128 }\r
129 div.content div.title:first-child {\r
130   margin-top: 0.0em;\r
131 }\r
132 div.content + div.title {\r
133   margin-top: 0.0em;\r
134 }\r
135 \r
136 div.sidebarblock > div.content {\r
137   background: #ffffee;\r
138   border: 1px solid silver;\r
139   padding: 0.5em;\r
140 }\r
141 \r
142 div.listingblock > div.content {\r
143   border: 1px solid silver;\r
144   background: #f4f4f4;\r
145   padding: 0.5em;\r
146 }\r
147 \r
148 div.quoteblock > div.content {\r
149   padding-left: 2.0em;\r
150 }\r
151 div.quoteblock .attribution {\r
152   text-align: right;\r
153 }\r
154 \r
155 div.admonitionblock .icon {\r
156   vertical-align: top;\r
157   font-size: 1.1em;\r
158   font-weight: bold;\r
159   text-decoration: underline;\r
160   color: #527bbd;\r
161   padding-right: 0.5em;\r
162 }\r
163 div.admonitionblock td.content {\r
164   padding-left: 0.5em;\r
165   border-left: 2px solid silver;\r
166 }\r
167 \r
168 div.exampleblock > div.content {\r
169   border-left: 2px solid silver;\r
170   padding: 0.5em;\r
171 }\r
172 \r
173 div.verseblock div.content {\r
174   white-space: pre;\r
175 }\r
176 \r
177 div.imageblock div.content { padding-left: 0; }\r
178 div.imageblock img { border: 1px solid silver; }\r
179 span.image img { border-style: none; }\r
180 \r
181 dl {\r
182   margin-top: 0.8em;\r
183   margin-bottom: 0.8em;\r
184 }\r
185 dt {\r
186   margin-top: 0.5em;\r
187   margin-bottom: 0;\r
188   font-style: italic;\r
189 }\r
190 dd > *:first-child {\r
191   margin-top: 0;\r
192 }\r
193 \r
194 ul, ol {\r
195     list-style-position: outside;\r
196 }\r
197 ol.olist2 {\r
198   list-style-type: lower-alpha;\r
199 }\r
200 \r
201 div.tableblock > table {\r
202   border-color: #527bbd;\r
203   border-width: 3px;\r
204 }\r
205 thead {\r
206   font-family: sans-serif;\r
207   font-weight: bold;\r
208 }\r
209 tfoot {\r
210   font-weight: bold;\r
211 }\r
212 \r
213 div.hlist {\r
214   margin-top: 0.8em;\r
215   margin-bottom: 0.8em;\r
216 }\r
217 td.hlist1 {\r
218   vertical-align: top;\r
219   font-style: italic;\r
220   padding-right: 0.8em;\r
221 }\r
222 td.hlist2 {\r
223   vertical-align: top;\r
224 }\r
225 \r
226 @media print {\r
227   div#footer-badges { display: none; }\r
228 }\r
229 /* Workarounds for IE6's broken and incomplete CSS2. */\r
230 \r
231 div.sidebar-content {\r
232   background: #ffffee;\r
233   border: 1px solid silver;\r
234   padding: 0.5em;\r
235 }\r
236 div.sidebar-title, div.image-title {\r
237   font-family: sans-serif;\r
238   font-weight: bold;\r
239   margin-top: 0.0em;\r
240   margin-bottom: 0.5em;\r
241 }\r
242 \r
243 div.listingblock div.content {\r
244   border: 1px solid silver;\r
245   background: #f4f4f4;\r
246   padding: 0.5em;\r
247 }\r
248 \r
249 div.quoteblock-content {\r
250   padding-left: 2.0em;\r
251 }\r
252 \r
253 div.exampleblock-content {\r
254   border-left: 2px solid silver;\r
255   padding-left: 0.5em;\r
256 }\r
257 </style>\r
258 <title>git for CVS users</title>\r
259 </head>\r
260 <body>\r
261 <div id="header">\r
262 <h1>git for CVS users</h1>\r
263 </div>\r
264 <div id="preamble">\r
265 <div class="sectionbody">\r
266 <p>Ok, so you're a CVS user. That's ok, it's a treatable condition, and the\r
267 first step to recovery is admitting you have a problem. The fact that\r
268 you are reading this file means that you may be well on that path\r
269 already.</p>\r
270 <p>The thing about CVS is that it absolutely sucks as a source control\r
271 manager, and you'll thus be happy with almost anything else. git,\r
272 however, may be a bit <em>too</em> different (read: "good") for your taste, and\r
273 does a lot of things differently.</p>\r
274 <p>One particular suckage of CVS is very hard to work around: CVS is\r
275 basically a tool for tracking <em>file</em> history, while git is a tool for\r
276 tracking <em>project</em> history.  This sometimes causes problems if you are\r
277 used to doing very strange things in CVS, in particular if you're doing\r
278 things like making branches of just a subset of the project.  git can't\r
279 track that, since git never tracks things on the level of an individual\r
280 file, only on the whole project level.</p>\r
281 <p>The good news is that most people don't do that, and in fact most sane\r
282 people think it's a bug in CVS that makes it tag (and check in changes)\r
283 one file at a time.  So most projects you'll ever see will use CVS\r
284 <em>as if</em> it was sane.  In which case you'll find it very easy indeed to\r
285 move over to git.</p>\r
286 <p>First off: this is not a git tutorial. See\r
287 <a href="tutorial.html">Documentation/tutorial.txt</a> for how git\r
288 actually works. This is more of a random collection of gotcha's\r
289 and notes on converting from CVS to git.</p>\r
290 <p>Second: CVS has the notion of a "repository" as opposed to the thing\r
291 that you're actually working in (your working directory, or your\r
292 "checked out tree").  git does not have that notion at all, and all git\r
293 working directories <em>are</em> the repositories.  However, you can easily\r
294 emulate the CVS model by having one special "global repository", which\r
295 people can synchronize with.  See details later, but in the meantime\r
296 just keep in mind that with git, every checked out working tree will\r
297 have a full revision control history of its own.</p>\r
298 </div>\r
299 </div>\r
300 <h2>Importing a CVS archive</h2>\r
301 <div class="sectionbody">\r
302 <p>Ok, you have an old project, and you want to at least give git a chance\r
303 to see how it performs. The first thing you want to do (after you've\r
304 gone through the git tutorial, and generally familiarized yourself with\r
305 how to commit stuff etc in git) is to create a git'ified version of your\r
306 CVS archive.</p>\r
307 <p>Happily, that's very easy indeed. git will do it for you, although git\r
308 will need the help of a program called "cvsps":</p>\r
309 <div class="literalblock">\r
310 <div class="content">\r
311 <pre><tt>http://www.cobite.com/cvsps/</tt></pre>\r
312 </div></div>\r
313 <p>which is not actually related to git at all, but which makes CVS usage\r
314 look almost sane (ie you almost certainly want to have it even if you\r
315 decide to stay with CVS). However, git will want <em>at least</em> version 2.1\r
316 of cvsps (available at the address above), and in fact will currently\r
317 refuse to work with anything else.</p>\r
318 <p>Once you've gotten (and installed) cvsps, you may or may not want to get\r
319 any more familiar with it, but make sure it is in your path. After that,\r
320 the magic command line is</p>\r
321 <div class="literalblock">\r
322 <div class="content">\r
323 <pre><tt>git cvsimport -v -d &lt;cvsroot&gt; -C &lt;destination&gt; &lt;module&gt;</tt></pre>\r
324 </div></div>\r
325 <p>which will do exactly what you'd think it does: it will create a git\r
326 archive of the named CVS module. The new archive will be created in the\r
327 subdirectory named &lt;destination&gt;; it'll be created if it doesn't exist.\r
328 Default is the local directory.</p>\r
329 <p>It can take some time to actually do the conversion for a large archive\r
330 since it involves checking out from CVS every revision of every file,\r
331 and the conversion script is reasonably chatty unless you omit the <em>-v</em>\r
332 option, but on some not very scientific tests it averaged about twenty\r
333 revisions per second, so a medium-sized project should not take more\r
334 than a couple of minutes.  For larger projects or remote repositories,\r
335 the process may take longer.</p>\r
336 <p>After the (initial) import is done, the CVS archive's current head\r
337 revision will be checked out &#8212; thus, you can start adding your own\r
338 changes right away.</p>\r
339 <p>The import is incremental, i.e. if you call it again next month it'll\r
340 fetch any CVS updates that have been happening in the meantime. The\r
341 cut-off is date-based, so don't change the branches that were imported\r
342 from CVS.</p>\r
343 <p>You can merge those updates (or, in fact, a different CVS branch) into\r
344 your main branch:</p>\r
345 <div class="literalblock">\r
346 <div class="content">\r
347 <pre><tt>git resolve HEAD origin "merge with current CVS HEAD"</tt></pre>\r
348 </div></div>\r
349 <p>The HEAD revision from CVS is named "origin", not "HEAD", because git\r
350 already uses "HEAD". (If you don't like <em>origin</em>, use cvsimport's\r
351 <em>-o</em> option to change it.)</p>\r
352 </div>\r
353 <h2>Emulating CVS behaviour</h2>\r
354 <div class="sectionbody">\r
355 <p>So, by now you are convinced you absolutely want to work with git, but\r
356 at the same time you absolutely have to have a central repository.\r
357 Step back and think again. Okay, you still need a single central\r
358 repository? There are several ways to go about that:</p>\r
359 <ol>\r
360 <li>\r
361 <p>\r
362 Designate a person responsible to pull all branches. Make the\r
363 repository of this person public, and make every team member\r
364 pull regularly from it.\r
365 </p>\r
366 </li>\r
367 <li>\r
368 <p>\r
369 Set up a public repository with read/write access for every team\r
370 member. Use "git pull/push" as you used "cvs update/commit".  Be\r
371 sure that your repository is up to date before pushing, just\r
372 like you used to do with "cvs commit"; your push will fail if\r
373 what you are pushing is not up to date.\r
374 </p>\r
375 </li>\r
376 <li>\r
377 <p>\r
378 Make the repository of every team member public. It is the\r
379 responsibility of each single member to pull from every other\r
380 team member.\r
381 </p>\r
382 </li>\r
383 </ol>\r
384 </div>\r
385 <h2>CVS annotate</h2>\r
386 <div class="sectionbody">\r
387 <p>So, something has gone wrong, and you don't know whom to blame, and\r
388 you're an ex-CVS user and used to do "cvs annotate" to see who caused\r
389 the breakage. You're looking for the "git annotate", and it's just\r
390 claiming not to find such a script. You're annoyed.</p>\r
391 <p>Yes, that's right.  Core git doesn't do "annotate", although it's\r
392 technically possible, and there are at least two specialized scripts out\r
393 there that can be used to get equivalent information (see the git\r
394 mailing list archives for details).</p>\r
395 <p>git has a couple of alternatives, though, that you may find sufficient\r
396 or even superior depending on your use.  One is called "git-whatchanged"\r
397 (for obvious reasons) and the other one is called "pickaxe" ("a tool for\r
398 the software archaeologist").</p>\r
399 <p>The "git-whatchanged" script is a truly trivial script that can give you\r
400 a good overview of what has changed in a file or a directory (or an\r
401 arbitrary list of files or directories).  The "pickaxe" support is an\r
402 additional layer that can be used to further specify exactly what you're\r
403 looking for, if you already know the specific area that changed.</p>\r
404 <p>Let's step back a bit and think about the reason why you would\r
405 want to do "cvs annotate a-file.c" to begin with.</p>\r
406 <p>You would use "cvs annotate" on a file when you have trouble\r
407 with a function (or even a single "if" statement in a function)\r
408 that happens to be defined in the file, which does not do what\r
409 you want it to do.  And you would want to find out why it was\r
410 written that way, because you are about to modify it to suit\r
411 your needs, and at the same time you do not want to break its\r
412 current callers.  For that, you are trying to find out why the\r
413 original author did things that way in the original context.</p>\r
414 <p>Many times, it may be enough to see the commit log messages of\r
415 commits that touch the file in question, possibly along with the\r
416 patches themselves, like this:</p>\r
417 <div class="literalblock">\r
418 <div class="content">\r
419 <pre><tt>$ git-whatchanged -p a-file.c</tt></pre>\r
420 </div></div>\r
421 <p>This will show log messages and patches for each commit that\r
422 touches a-file.</p>\r
423 <p>This, however, may not be very useful when this file has many\r
424 modifications that are not related to the piece of code you are\r
425 interested in.  You would see many log messages and patches that\r
426 do not have anything to do with the piece of code you are\r
427 interested in.  As an example, assuming that you have this piece\r
428 of code that you are interested in in the HEAD version:</p>\r
429 <div class="literalblock">\r
430 <div class="content">\r
431 <pre><tt>if (frotz) {\r
432         nitfol();\r
433 }</tt></pre>\r
434 </div></div>\r
435 <p>you would use git-rev-list and git-diff-tree like this:</p>\r
436 <div class="literalblock">\r
437 <div class="content">\r
438 <pre><tt>$ git-rev-list HEAD |\r
439   git-diff-tree --stdin -v -p -S'if (frotz) {\r
440         nitfol();\r
441 }'</tt></pre>\r
442 </div></div>\r
443 <p>We have already talked about the "--stdin" form of git-diff-tree\r
444 command that reads the list of commits and compares each commit\r
445 with its parents (otherwise you should go back and read the tutorial).\r
446 The git-whatchanged command internally runs\r
447 the equivalent of the above command, and can be used like this:</p>\r
448 <div class="literalblock">\r
449 <div class="content">\r
450 <pre><tt>$ git-whatchanged -p -S'if (frotz) {\r
451         nitfol();\r
452 }'</tt></pre>\r
453 </div></div>\r
454 <p>When the -S option is used, git-diff-tree command outputs\r
455 differences between two commits only if one tree has the\r
456 specified string in a file and the corresponding file in the\r
457 other tree does not.  The above example looks for a commit that\r
458 has the "if" statement in it in a file, but its parent commit\r
459 does not have it in the same shape in the corresponding file (or\r
460 the other way around, where the parent has it and the commit\r
461 does not), and the differences between them are shown, along\r
462 with the commit message (thanks to the -v flag).  It does not\r
463 show anything for commits that do not touch this "if" statement.</p>\r
464 <p>Also, in the original context, the same statement might have\r
465 appeared at first in a different file and later the file was\r
466 renamed to "a-file.c".  CVS annotate would not help you to go\r
467 back across such a rename, but git would still help you in such\r
468 a situation.  For that, you can give the -C flag to\r
469 git-diff-tree, like this:</p>\r
470 <div class="literalblock">\r
471 <div class="content">\r
472 <pre><tt>$ git-whatchanged -p -C -S'if (frotz) {\r
473         nitfol();\r
474 }'</tt></pre>\r
475 </div></div>\r
476 <p>When the -C flag is used, file renames and copies are followed.\r
477 So if the "if" statement in question happens to be in "a-file.c"\r
478 in the current HEAD commit, even if the file was originally\r
479 called "o-file.c" and then renamed in an earlier commit, or if\r
480 the file was created by copying an existing "o-file.c" in an\r
481 earlier commit, you will not lose track.  If the "if" statement\r
482 did not change across such a rename or copy, then the commit that\r
483 does rename or copy would not show in the output, and if the\r
484 "if" statement was modified while the file was still called\r
485 "o-file.c", it would find the commit that changed the statement\r
486 when it was in "o-file.c".</p>\r
487 <div class="admonitionblock">\r
488 <table><tr>\r
489 <td class="icon">\r
490 <div class="title">Note</div>\r
491 </td>\r
492 <td class="content">The current version of "git-diff-tree -C" is not eager\r
493   enough to find copies, and it will miss the fact that a-file.c\r
494   was created by copying o-file.c unless o-file.c was somehow\r
495   changed in the same commit.</td>\r
496 </tr></table>\r
497 </div>\r
498 <p>You can use the &#8212;pickaxe-all flag in addition to the -S flag.\r
499 This causes the differences from all the files contained in\r
500 those two commits, not just the differences between the files\r
501 that contain this changed "if" statement:</p>\r
502 <div class="literalblock">\r
503 <div class="content">\r
504 <pre><tt>$ git-whatchanged -p -C -S'if (frotz) {\r
505         nitfol();\r
506 }' --pickaxe-all</tt></pre>\r
507 </div></div>\r
508 <div class="admonitionblock">\r
509 <table><tr>\r
510 <td class="icon">\r
511 <div class="title">Note</div>\r
512 </td>\r
513 <td class="content">This option is called "&#8212;pickaxe-all" because -S\r
514   option is internally called "pickaxe", a tool for software\r
515   archaeologists.</td>\r
516 </tr></table>\r
517 </div>\r
518 </div>\r
519 <div id="footer">\r
520 <div id="footer-text">\r
521 Last updated 06-Jan-2006 17:12:56 PDT\r
522 </div>\r
523 </div>\r
524 </body>\r
525 </html>\r