cvs-migration document: make the need for "push" more obvious
[git/jnareb-git.git] / Documentation / cvs-migration.txt
blob9c2a395e5ac9435f5d42d10837694e2fe13d6c63
1 git for CVS users
2 =================
4 So you're a CVS user. That's OK, it's a treatable condition.  The job of
5 this document is to put you on the road to recovery, by helping you
6 convert an existing cvs repository to git, and by showing you how to use a
7 git repository in a cvs-like fashion.
9 Some basic familiarity with git is required.  This
10 link:tutorial.html[tutorial introduction to git] should be sufficient.
12 First, note some ways that git differs from CVS:
14   * Commits are atomic and project-wide, not per-file as in CVS.
16   * Offline work is supported: you can make multiple commits locally,
17     then submit them when you're ready.
19   * Branching is fast and easy.
21   * Every working tree contains a repository with a full copy of the
22     project history, and no repository is inherently more important than
23     any other.  However, you can emulate the CVS model by designating a
24     single shared repository which people can synchronize with; see below
25     for details.
27   * Since every working tree contains a repository, a commit in your
28     private repository will not publish your changes; it will only create
29     a revision. You have to "push" your changes to a public repository to
30     make them visible to others.
32 Importing a CVS archive
33 -----------------------
35 First, install version 2.1 or higher of cvsps from
36 link:http://www.cobite.com/cvsps/[http://www.cobite.com/cvsps/] and make
37 sure it is in your path.  The magic command line is then
39 -------------------------------------------
40 $ git cvsimport -v -d <cvsroot> -C <destination> <module>
41 -------------------------------------------
43 This puts a git archive of the named CVS module in the directory
44 <destination>, which will be created if necessary.  The -v option makes
45 the conversion script very chatty.
47 The import checks out from CVS every revision of every file.  Reportedly
48 cvsimport can average some twenty revisions per second, so for a
49 medium-sized project this should not take more than a couple of minutes.
50 Larger projects or remote repositories may take longer.
52 The main trunk is stored in the git branch named `origin`, and additional
53 CVS branches are stored in git branches with the same names.  The most
54 recent version of the main trunk is also left checked out on the `master`
55 branch, so you can start adding your own changes right away.
57 The import is incremental, so if you call it again next month it will
58 fetch any CVS updates that have been made in the meantime.  For this to
59 work, you must not modify the imported branches; instead, create new
60 branches for your own changes, and merge in the imported branches as
61 necessary.
63 Development Models
64 ------------------
66 CVS users are accustomed to giving a group of developers commit access to
67 a common repository.  In the next section we'll explain how to do this
68 with git.  However, the distributed nature of git allows other development
69 models, and you may want to first consider whether one of them might be a
70 better fit for your project.
72 For example, you can choose a single person to maintain the project's
73 primary public repository.  Other developers then clone this repository
74 and each work in their own clone.  When they have a series of changes that
75 they're happy with, they ask the maintainer to pull from the branch
76 containing the changes.  The maintainer reviews their changes and pulls
77 them into the primary repository, which other developers pull from as
78 necessary to stay coordinated.  The Linux kernel and other projects use
79 variants of this model.
81 With a small group, developers may just pull changes from each other's
82 repositories without the need for a central maintainer.
84 Emulating the CVS Development Model
85 -----------------------------------
87 Start with an ordinary git working directory containing the project, and
88 remove the checked-out files, keeping just the bare .git directory:
90 ------------------------------------------------
91 $ mv project/.git /pub/repo.git
92 $ rm -r project/
93 ------------------------------------------------
95 Next, give every team member read/write access to this repository.  One
96 easy way to do this is to give all the team members ssh access to the
97 machine where the repository is hosted.  If you don't want to give them a
98 full shell on the machine, there is a restricted shell which only allows
99 users to do git pushes and pulls; see gitlink:git-shell[1].
101 Put all the committers in the same group, and make the repository
102 writable by that group:
104 ------------------------------------------------
105 $ chgrp -R $group repo.git
106 $ find repo.git -mindepth 1 -type d |xargs chmod ug+rwx,g+s
107 $ GIT_DIR=repo.git git repo-config core.sharedrepository true
108 ------------------------------------------------
110 Make sure committers have a umask of at most 027, so that the directories
111 they create are writable and searchable by other group members.
113 Suppose this repository is now set up in /pub/repo.git on the host
114 foo.com.  Then as an individual committer you can clone the shared
115 repository:
117 ------------------------------------------------
118 $ git clone foo.com:/pub/repo.git/ my-project
119 $ cd my-project
120 ------------------------------------------------
122 and hack away.  The equivalent of `cvs update` is
124 ------------------------------------------------
125 $ git pull origin
126 ------------------------------------------------
128 which merges in any work that others might have done since the clone
129 operation.
131 [NOTE]
132 ================================
133 The first `git clone` places the following in the
134 `my-project/.git/remotes/origin` file, and that's why the previous step
135 and the next step both work.
136 ------------
137 URL: foo.com:/pub/project.git/ my-project
138 Pull: master:origin
139 ------------
140 ================================
142 You can update the shared repository with your changes using:
144 ------------------------------------------------
145 $ git push origin master
146 ------------------------------------------------
148 If someone else has updated the repository more recently, `git push`, like
149 `cvs commit`, will complain, in which case you must pull any changes
150 before attempting the push again.
152 In the `git push` command above we specify the name of the remote branch
153 to update (`master`).  If we leave that out, `git push` tries to update
154 any branches in the remote repository that have the same name as a branch
155 in the local repository.  So the last `push` can be done with either of:
157 ------------
158 $ git push origin
159 $ git push repo.shared.xz:/pub/scm/project.git/
160 ------------
162 as long as the shared repository does not have any branches
163 other than `master`.
165 [NOTE]
166 ============
167 Because of this behavior, if the shared repository and the developer's
168 repository both have branches named `origin`, then a push like the above
169 attempts to update the `origin` branch in the shared repository from the
170 developer's `origin` branch.  The results may be unexpected, so it's
171 usually best to remove any branch named `origin` from the shared
172 repository.
173 ============
175 Advanced Shared Repository Management
176 -------------------------------------
178 Git allows you to specify scripts called "hooks" to be run at certain
179 points.  You can use these, for example, to send all commits to the shared
180 repository to a mailing list.  See link:hooks.html[Hooks used by git].
182 You can enforce finer grained permissions using update hooks.  See
183 link:howto/update-hook-example.txt[Controlling access to branches using
184 update hooks].
186 CVS annotate
187 ------------
189 So, something has gone wrong, and you don't know whom to blame, and
190 you're an ex-CVS user and used to do "cvs annotate" to see who caused
191 the breakage. You're looking for the "git annotate", and it's just
192 claiming not to find such a script. You're annoyed.
194 Yes, that's right.  Core git doesn't do "annotate", although it's
195 technically possible, and there are at least two specialized scripts out
196 there that can be used to get equivalent information (see the git
197 mailing list archives for details). 
199 git has a couple of alternatives, though, that you may find sufficient
200 or even superior depending on your use.  One is called "git-whatchanged"
201 (for obvious reasons) and the other one is called "pickaxe" ("a tool for
202 the software archaeologist"). 
204 The "git-whatchanged" script is a truly trivial script that can give you
205 a good overview of what has changed in a file or a directory (or an
206 arbitrary list of files or directories).  The "pickaxe" support is an
207 additional layer that can be used to further specify exactly what you're
208 looking for, if you already know the specific area that changed.
210 Let's step back a bit and think about the reason why you would
211 want to do "cvs annotate a-file.c" to begin with.
213 You would use "cvs annotate" on a file when you have trouble
214 with a function (or even a single "if" statement in a function)
215 that happens to be defined in the file, which does not do what
216 you want it to do.  And you would want to find out why it was
217 written that way, because you are about to modify it to suit
218 your needs, and at the same time you do not want to break its
219 current callers.  For that, you are trying to find out why the
220 original author did things that way in the original context.
222 Many times, it may be enough to see the commit log messages of
223 commits that touch the file in question, possibly along with the
224 patches themselves, like this:
226         $ git-whatchanged -p a-file.c
228 This will show log messages and patches for each commit that
229 touches a-file.
231 This, however, may not be very useful when this file has many
232 modifications that are not related to the piece of code you are
233 interested in.  You would see many log messages and patches that
234 do not have anything to do with the piece of code you are
235 interested in.  As an example, assuming that you have this piece
236 of code that you are interested in in the HEAD version:
238         if (frotz) {
239                 nitfol();
240         }
242 you would use git-rev-list and git-diff-tree like this:
244         $ git-rev-list HEAD |
245           git-diff-tree --stdin -v -p -S'if (frotz) {
246                 nitfol();
247         }'
249 We have already talked about the "\--stdin" form of git-diff-tree
250 command that reads the list of commits and compares each commit
251 with its parents (otherwise you should go back and read the tutorial).
252 The git-whatchanged command internally runs
253 the equivalent of the above command, and can be used like this:
255         $ git-whatchanged -p -S'if (frotz) {
256                 nitfol();
257         }'
259 When the -S option is used, git-diff-tree command outputs
260 differences between two commits only if one tree has the
261 specified string in a file and the corresponding file in the
262 other tree does not.  The above example looks for a commit that
263 has the "if" statement in it in a file, but its parent commit
264 does not have it in the same shape in the corresponding file (or
265 the other way around, where the parent has it and the commit
266 does not), and the differences between them are shown, along
267 with the commit message (thanks to the -v flag).  It does not
268 show anything for commits that do not touch this "if" statement.
270 Also, in the original context, the same statement might have
271 appeared at first in a different file and later the file was
272 renamed to "a-file.c".  CVS annotate would not help you to go
273 back across such a rename, but git would still help you in such
274 a situation.  For that, you can give the -C flag to
275 git-diff-tree, like this:
277         $ git-whatchanged -p -C -S'if (frotz) {
278                 nitfol();
279         }'
281 When the -C flag is used, file renames and copies are followed.
282 So if the "if" statement in question happens to be in "a-file.c"
283 in the current HEAD commit, even if the file was originally
284 called "o-file.c" and then renamed in an earlier commit, or if
285 the file was created by copying an existing "o-file.c" in an
286 earlier commit, you will not lose track.  If the "if" statement
287 did not change across such a rename or copy, then the commit that
288 does rename or copy would not show in the output, and if the
289 "if" statement was modified while the file was still called
290 "o-file.c", it would find the commit that changed the statement
291 when it was in "o-file.c".
293 NOTE: The current version of "git-diff-tree -C" is not eager
294   enough to find copies, and it will miss the fact that a-file.c
295   was created by copying o-file.c unless o-file.c was somehow
296   changed in the same commit.
298 You can use the --pickaxe-all flag in addition to the -S flag.
299 This causes the differences from all the files contained in
300 those two commits, not just the differences between the files
301 that contain this changed "if" statement:
303         $ git-whatchanged -p -C -S'if (frotz) {
304                 nitfol();
305         }' --pickaxe-all
307 NOTE: This option is called "--pickaxe-all" because -S
308   option is internally called "pickaxe", a tool for software
309   archaeologists.