1
git for CVS users
2
=================
3
4
-Ok, so you're a CVS user. That's ok, it's a treatable condition, and the
5
-first step to recovery is admitting you have a problem. The fact that
6
-you are reading this file means that you may be well on that path
7
-already.
8
-
9
-The thing about CVS is that it absolutely sucks as a source control
10
-manager, and you'll thus be happy with almost anything else. git,
11
-however, may be a bit 'too' different (read: "good") for your taste, and
12
-does a lot of things differently.
13
-
14
-One particular suckage of CVS is very hard to work around: CVS is
15
-basically a tool for tracking 'file' history, while git is a tool for
16
-tracking 'project' history. This sometimes causes problems if you are
17
-used to doing very strange things in CVS, in particular if you're doing
18
-things like making branches of just a subset of the project. git can't
19
-track that, since git never tracks things on the level of an individual
20
-file, only on the whole project level.
21
-
22
-The good news is that most people don't do that, and in fact most sane
23
-people think it's a bug in CVS that makes it tag (and check in changes)
24
-one file at a time. So most projects you'll ever see will use CVS
25
-'as if' it was sane. In which case you'll find it very easy indeed to
26
-move over to git.
27
-
28
-First off: this is not a git tutorial. See
29
-link:tutorial.html[Documentation/tutorial.txt] for how git
30
-actually works. This is more of a random collection of gotcha's
31
-and notes on converting from CVS to git.
32
-
33
-Second: CVS has the notion of a "repository" as opposed to the thing
34
-that you're actually working in (your working directory, or your
35
-"checked out tree"). git does not have that notion at all, and all git
36
-working directories 'are' the repositories. However, you can easily
37
-emulate the CVS model by having one special "global repository", which
38
-people can synchronize with. See details later, but in the meantime
39
-just keep in mind that with git, every checked out working tree will
40
-have a full revision control history of its own.
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.
8
9
+Some basic familiarity with git is required. This
10
+link:tutorial.html[tutorial introduction to git] should be sufficient.
11
43
-Importing a CVS archive
44
------------------------
45
-
46
-Ok, you have an old project, and you want to at least give git a chance
47
-to see how it performs. The first thing you want to do (after you've
48
-gone through the git tutorial, and generally familiarized yourself with
49
-how to commit stuff etc in git) is to create a git'ified version of your
50
-CVS archive.
51
-
52
-Happily, that's very easy indeed. git will do it for you, although git
53
-will need the help of a program called "cvsps":
54
-
55
- http://www.cobite.com/cvsps/
56
-
57
-which is not actually related to git at all, but which makes CVS usage
58
-look almost sane (ie you almost certainly want to have it even if you
59
-decide to stay with CVS). However, git will want 'at least' version 2.1
60
-of cvsps (available at the address above), and in fact will currently
61
-refuse to work with anything else.
62
-
63
-Once you've gotten (and installed) cvsps, you may or may not want to get
64
-any more familiar with it, but make sure it is in your path. After that,
65
-the magic command line is
66
-
67
- git cvsimport -v -d <cvsroot> -C <destination> <module>
68
-
69
-which will do exactly what you'd think it does: it will create a git
70
-archive of the named CVS module. The new archive will be created in the
71
-subdirectory named <destination>; it'll be created if it doesn't exist.
72
-Default is the local directory.
12
+First, note some ways that git differs from CVS:
13
74
-It can take some time to actually do the conversion for a large archive
75
-since it involves checking out from CVS every revision of every file,
76
-and the conversion script is reasonably chatty unless you omit the '-v'
77
-option, but on some not very scientific tests it averaged about twenty
78
-revisions per second, so a medium-sized project should not take more
79
-than a couple of minutes. For larger projects or remote repositories,
80
-the process may take longer.
14
+ * Commits are atomic and project-wide, not per-file as in CVS.
15
82
-After the (initial) import is done, the CVS archive's current head
83
-revision will be checked out -- thus, you can start adding your own
84
-changes right away.
16
+ * Offline work is supported: you can make multiple commits locally,
17
+ then submit them when you're ready.
18
86
-The import is incremental, i.e. if you call it again next month it'll
87
-fetch any CVS updates that have been happening in the meantime. The
88
-cut-off is date-based, so don't change the branches that were imported
89
-from CVS.
19
+ * Branching is fast and easy.
20
91
-You can merge those updates (or, in fact, a different CVS branch) into
92
-your main branch:
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.
26
94
- git resolve HEAD origin "merge with current CVS HEAD"
95
-
96
-The HEAD revision from CVS is named "origin", not "HEAD", because git
97
-already uses "HEAD". (If you don't like 'origin', use cvsimport's
98
-'-o' option to change it.)
99
-
100
-
101
-Emulating CVS behaviour
27
+Importing a CVS archive
28
-----------------------
29
30
+First, install version 2.1 or higher of cvsps from
31
+link:http://www.cobite.com/cvsps/[http://www.cobite.com/cvsps/] and make
32
+sure it is in your path. The magic command line is then
33
+
34
+-------------------------------------------
35
+$ git cvsimport -v -d <cvsroot> -C <destination> <module>
36
+-------------------------------------------
37
+
38
+This puts a git archive of the named CVS module in the directory
39
+<destination>, which will be created if necessary. The -v option makes
40
+the conversion script very chatty.
41
+
42
+The import checks out from CVS every revision of every file. Reportedly
43
+cvsimport can average some twenty revisions per second, so for a
44
+medium-sized project this should not take more than a couple of minutes.
45
+Larger projects or remote repositories may take longer.
46
+
47
+The main trunk is stored in the git branch named `origin`, and additional
48
+CVS branches are stored in git branches with the same names. The most
49
+recent version of the main trunk is also left checked out on the `master`
50
+branch, so you can start adding your own changes right away.
51
+
52
+The import is incremental, so if you call it again next month it will
53
+fetch any CVS updates that have been made in the meantime. For this to
54
+work, you must not modify the imported branches; instead, create new
55
+branches for your own changes, and merge in the imported branches as
56
+necessary.
57
+
58
+Development Models
59
+------------------
60
+
61
+CVS users are accustomed to giving a group of developers commit access to
62
+a common repository. In the next section we'll explain how to do this
63
+with git. However, the distributed nature of git allows other development
64
+models, and you may want to first consider whether one of them might be a
65
+better fit for your project.
66
+
67
+For example, you can choose a single person to maintain the project's
68
+primary public repository. Other developers then clone this repository
69
+and each work in their own clone. When they have a series of changes that
70
+they're happy with, they ask the maintainer to pull from the branch
71
+containing the changes. The maintainer reviews their changes and pulls
72
+them into the primary repository, which other developers pull from as
73
+necessary to stay coordinated. The Linux kernel and other projects use
74
+variants of this model.
75
+
76
+With a small group, developers may just pull changes from each other's
77
+repositories without the need for a central maintainer.
78
+
79
+Emulating the CVS Development Model
80
+-----------------------------------
81
+
82
+Start with an ordinary git working directory containing the project, and
83
+remove the checked-out files, keeping just the bare .git directory:
84
+
85
+------------------------------------------------
86
+$ mv project/.git /pub/repo.git
87
+$ rm -r project/
88
+------------------------------------------------
89
+
90
+Next, give every team member read/write access to this repository. One
91
+easy way to do this is to give all the team members ssh access to the
92
+machine where the repository is hosted. If you don't want to give them a
93
+full shell on the machine, there is a restricted shell which only allows
94
+users to do git pushes and pulls; see gitlink:git-shell[1].
95
+
96
+Put all the committers should in the same group, and make the repository
97
+writable by that group:
98
+
99
+------------------------------------------------
100
+$ chgrp -R $group repo.git
101
+$ find repo.git -mindepth 1 -type d |xargs chmod ug+rwx,g+s
102
+$ GIT_DIR=repo.git git repo-config core.sharedrepository true
103
+------------------------------------------------
104
+
105
+Make sure committers have a umask of at most 027, so that the directories
106
+they create are writable and searchable by other group members.
107
+
108
+Suppose this repository is now set up in /pub/repo.git on the host
109
+foo.com. Then as an individual commiter you can clone the shared
110
+repository:
111
+
112
+------------------------------------------------
113
+$ git clone foo.com:/pub/repo.git/ my-project
114
+$ cd my-project
115
+------------------------------------------------
116
+
117
+and hack away. The equivalent of `cvs update` is
118
+
119
+------------------------------------------------
120
+$ git pull origin
121
+------------------------------------------------
122
+
123
+which merges in any work that others might have done since the clone
124
+operation.
125
+
126
+[NOTE]
127
+================================
128
+The first `git clone` places the following in the
129
+`my-project/.git/remotes/origin` file, and that's why the previous step
130
+and the next step both work.
131
+------------
132
+URL: foo.com:/pub/project.git/ my-project
133
+Pull: master:origin
134
+------------
135
+================================
136
+
137
+You can update the shared repository with your changes using:
138
105
-So, by now you are convinced you absolutely want to work with git, but
106
-at the same time you absolutely have to have a central repository.
107
-Step back and think again. Okay, you still need a single central
108
-repository? There are several ways to go about that:
139
+------------------------------------------------
140
+$ git push origin master
141
+------------------------------------------------
142
110
-1. Designate a person responsible to pull all branches. Make the
111
-repository of this person public, and make every team member
112
-pull regularly from it.
143
+If some else has updated the repository more recently, `git push`, like
144
+`cvs commit`, will complain, in which case you must pull any changes
145
+before attempting the push again.
146
114
-2. Set up a public repository with read/write access for every team
115
-member. Use "git pull/push" as you used "cvs update/commit". Be
116
-sure that your repository is up to date before pushing, just
117
-like you used to do with "cvs commit"; your push will fail if
118
-what you are pushing is not up to date.
147
+In the `git push` command above we specify the name of the remote branch
148
+to update (`master`). If we leave that out, `git push` tries to update
149
+any branches in the remote repository that have the same name as a branch
150
+in the local repository. So the last `push` can be done with either of:
151
120
-3. Make the repository of every team member public. It is the
121
-responsibility of each single member to pull from every other
122
-team member.
152
+------------
153
+$ git push origin
154
+$ git push repo.shared.xz:/pub/scm/project.git/
155
+------------
156
157
+as long as the shared repository does not have any branches
158
+other than `master`.
159
+
160
+[NOTE]
161
+============
162
+Because of this behaviour, if the shared repository and the developer's
163
+repository both have branches named `origin`, then a push like the above
164
+attempts to update the `origin` branch in the shared repository from the
165
+developer's `origin` branch. The results may be unexpected, so it's
166
+usually best to remove any branch named `origin` from the shared
167
+repository.
168
+============
169
+
170
+Advanced Shared Repository Management
171
+-------------------------------------
172
+
173
+Git allows you to specify scripts called "hooks" to be run at certain
174
+points. You can use these, for example, to send all commits to the shared
175
+repository to a mailing list. See link:hooks.txt[Hooks used by git].
176
+
177
+You can enforce finer grained permissions using update hooks. See
178
+link:howto/update-hook-example.txt[Controlling access to branches using
179
+update hooks].
180
181
CVS annotate
182
------------