Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 1 | gitcvs-migration(7) |
| 2 | =================== |
| 3 | |
| 4 | NAME |
| 5 | ---- |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 6 | gitcvs-migration - Git for CVS users |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 7 | |
| 8 | SYNOPSIS |
| 9 | -------- |
Junio C Hamano | 15567bc | 2011-07-23 00:51:59 | [diff] [blame] | 10 | [verse] |
| 11 | 'git cvsimport' * |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 12 | |
| 13 | DESCRIPTION |
| 14 | ----------- |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 15 | |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 16 | Git differs from CVS in that every working tree contains a repository with |
| 17 | a full copy of the project history, and no repository is inherently more |
| 18 | important than any other. However, you can emulate the CVS model by |
| 19 | designating a single shared repository which people can synchronize with; |
| 20 | this document explains how to do that. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 21 | |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 22 | Some basic familiarity with Git is required. Having gone through |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 23 | linkgit:gittutorial[7] and |
| 24 | linkgit:gitglossary[7] should be sufficient. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 25 | |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 26 | Developing against a shared repository |
| 27 | -------------------------------------- |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 28 | |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 29 | Suppose a shared repository is set up in /pub/repo.git on the host |
| 30 | foo.com. Then as an individual committer you can clone the shared |
| 31 | repository over ssh with: |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 32 | |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 33 | ------------------------------------------------ |
| 34 | $ git clone foo.com:/pub/repo.git/ my-project |
| 35 | $ cd my-project |
| 36 | ------------------------------------------------ |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 37 | |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 38 | and hack away. The equivalent of 'cvs update' is |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 39 | |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 40 | ------------------------------------------------ |
| 41 | $ git pull origin |
| 42 | ------------------------------------------------ |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 43 | |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 44 | which merges in any work that others might have done since the clone |
| 45 | operation. If there are uncommitted changes in your working tree, commit |
| 46 | them first before running git pull. |
| 47 | |
| 48 | [NOTE] |
| 49 | ================================ |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 50 | The 'pull' command knows where to get updates from because of certain |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 51 | configuration variables that were set by the first 'git clone' |
Junio C Hamano | 35738e8 | 2008-01-07 07:55:46 | [diff] [blame] | 52 | command; see `git config -l` and the linkgit:git-config[1] man |
Junio C Hamano | d3361ad | 2007-01-01 03:20:24 | [diff] [blame] | 53 | page for details. |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 54 | ================================ |
| 55 | |
Junio C Hamano | 96010b2 | 2006-12-09 21:15:46 | [diff] [blame] | 56 | You can update the shared repository with your changes by first committing |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 57 | your changes, and then using the 'git push' command: |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 58 | |
| 59 | ------------------------------------------------ |
| 60 | $ git push origin master |
| 61 | ------------------------------------------------ |
| 62 | |
| 63 | to "push" those commits to the shared repository. If someone else has |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 64 | updated the repository more recently, 'git push', like 'cvs commit', will |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 65 | complain, in which case you must pull any changes before attempting the |
| 66 | push again. |
| 67 | |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 68 | In the 'git push' command above we specify the name of the remote branch |
| 69 | to update (`master`). If we leave that out, 'git push' tries to update |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 70 | any branches in the remote repository that have the same name as a branch |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 71 | in the local repository. So the last 'push' can be done with either of: |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 72 | |
| 73 | ------------ |
| 74 | $ git push origin |
| 75 | $ git push foo.com:/pub/project.git/ |
| 76 | ------------ |
| 77 | |
| 78 | as long as the shared repository does not have any branches |
| 79 | other than `master`. |
| 80 | |
| 81 | Setting Up a Shared Repository |
| 82 | ------------------------------ |
| 83 | |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 84 | We assume you have already created a Git repository for your project, |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 85 | possibly created from scratch or from a tarball (see |
| 86 | linkgit:gittutorial[7]), or imported from an already existing CVS |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 87 | repository (see the next section). |
| 88 | |
Junio C Hamano | 96010b2 | 2006-12-09 21:15:46 | [diff] [blame] | 89 | Assume your existing repo is at /home/alice/myproject. Create a new "bare" |
| 90 | repository (a repository without a working tree) and fetch your project into |
| 91 | it: |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 92 | |
| 93 | ------------------------------------------------ |
Junio C Hamano | 96010b2 | 2006-12-09 21:15:46 | [diff] [blame] | 94 | $ mkdir /pub/my-repo.git |
| 95 | $ cd /pub/my-repo.git |
Junio C Hamano | 24351a8 | 2007-01-13 08:09:17 | [diff] [blame] | 96 | $ git --bare init --shared |
Junio C Hamano | 96010b2 | 2006-12-09 21:15:46 | [diff] [blame] | 97 | $ git --bare fetch /home/alice/myproject master:master |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 98 | ------------------------------------------------ |
| 99 | |
| 100 | Next, give every team member read/write access to this repository. One |
| 101 | easy way to do this is to give all the team members ssh access to the |
| 102 | machine where the repository is hosted. If you don't want to give them a |
| 103 | full shell on the machine, there is a restricted shell which only allows |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 104 | users to do Git pushes and pulls; see linkgit:git-shell[1]. |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 105 | |
| 106 | Put all the committers in the same group, and make the repository |
| 107 | writable by that group: |
| 108 | |
| 109 | ------------------------------------------------ |
Junio C Hamano | 96010b2 | 2006-12-09 21:15:46 | [diff] [blame] | 110 | $ chgrp -R $group /pub/my-repo.git |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 111 | ------------------------------------------------ |
| 112 | |
| 113 | Make sure committers have a umask of at most 027, so that the directories |
| 114 | they create are writable and searchable by other group members. |
Junio C Hamano | 353c3a9 | 2006-12-06 21:11:49 | [diff] [blame] | 115 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 116 | Importing a CVS archive |
| 117 | ----------------------- |
| 118 | |
Junio C Hamano | ad70bf0 | 2016-09-26 23:44:27 | [diff] [blame] | 119 | NOTE: These instructions use the `git-cvsimport` script which ships with |
| 120 | git, but other importers may provide better results. See the note in |
| 121 | linkgit:git-cvsimport[1] for other options. |
| 122 | |
Junio C Hamano | cfa7ad0 | 2006-01-31 07:10:49 | [diff] [blame] | 123 | First, install version 2.1 or higher of cvsps from |
Junio C Hamano | ad70bf0 | 2016-09-26 23:44:27 | [diff] [blame] | 124 | https://github.com/andreyvit/cvsps[https://github.com/andreyvit/cvsps] and make |
Junio C Hamano | 96010b2 | 2006-12-09 21:15:46 | [diff] [blame] | 125 | sure it is in your path. Then cd to a checked out CVS working directory |
Junio C Hamano | ea86833 | 2009-04-21 08:11:06 | [diff] [blame] | 126 | of the project you are interested in and run linkgit:git-cvsimport[1]: |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 127 | |
Junio C Hamano | cfa7ad0 | 2006-01-31 07:10:49 | [diff] [blame] | 128 | ------------------------------------------- |
Junio C Hamano | aa83a7d | 2007-03-05 02:37:29 | [diff] [blame] | 129 | $ git cvsimport -C <destination> <module> |
Junio C Hamano | cfa7ad0 | 2006-01-31 07:10:49 | [diff] [blame] | 130 | ------------------------------------------- |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 131 | |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 132 | This puts a Git archive of the named CVS module in the directory |
Junio C Hamano | 96010b2 | 2006-12-09 21:15:46 | [diff] [blame] | 133 | <destination>, which will be created if necessary. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 134 | |
Junio C Hamano | cfa7ad0 | 2006-01-31 07:10:49 | [diff] [blame] | 135 | The import checks out from CVS every revision of every file. Reportedly |
| 136 | cvsimport can average some twenty revisions per second, so for a |
| 137 | medium-sized project this should not take more than a couple of minutes. |
| 138 | Larger projects or remote repositories may take longer. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 139 | |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 140 | The main trunk is stored in the Git branch named `origin`, and additional |
| 141 | CVS branches are stored in Git branches with the same names. The most |
Junio C Hamano | cfa7ad0 | 2006-01-31 07:10:49 | [diff] [blame] | 142 | recent version of the main trunk is also left checked out on the `master` |
| 143 | branch, so you can start adding your own changes right away. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 144 | |
Junio C Hamano | cfa7ad0 | 2006-01-31 07:10:49 | [diff] [blame] | 145 | The import is incremental, so if you call it again next month it will |
| 146 | fetch any CVS updates that have been made in the meantime. For this to |
| 147 | work, you must not modify the imported branches; instead, create new |
| 148 | branches for your own changes, and merge in the imported branches as |
| 149 | necessary. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 150 | |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 151 | If you want a shared repository, you will need to make a bare clone |
| 152 | of the imported directory, as described above. Then treat the imported |
| 153 | directory as another development clone for purposes of merging |
| 154 | incremental imports. |
| 155 | |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 156 | Advanced Shared Repository Management |
| 157 | ------------------------------------- |
| 158 | |
| 159 | Git allows you to specify scripts called "hooks" to be run at certain |
| 160 | points. You can use these, for example, to send all commits to the shared |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 161 | repository to a mailing list. See linkgit:githooks[5]. |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 162 | |
| 163 | You can enforce finer grained permissions using update hooks. See |
Junio C Hamano | e6f28d0 | 2013-09-17 21:34:00 | [diff] [blame] | 164 | link:howto/update-hook-example.html[Controlling access to branches using |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 165 | update hooks]. |
| 166 | |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 167 | Providing CVS Access to a Git Repository |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 168 | ---------------------------------------- |
| 169 | |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 170 | It is also possible to provide true CVS access to a Git repository, so |
Junio C Hamano | 35738e8 | 2008-01-07 07:55:46 | [diff] [blame] | 171 | that developers can still use CVS; see linkgit:git-cvsserver[1] for |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 172 | details. |
| 173 | |
| 174 | Alternative Development Models |
| 175 | ------------------------------ |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 176 | |
Junio C Hamano | cfa7ad0 | 2006-01-31 07:10:49 | [diff] [blame] | 177 | CVS users are accustomed to giving a group of developers commit access to |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 178 | a common repository. As we've seen, this is also possible with Git. |
| 179 | However, the distributed nature of Git allows other development models, |
Junio C Hamano | 5102d9a | 2006-12-08 07:23:46 | [diff] [blame] | 180 | and you may want to first consider whether one of them might be a better |
| 181 | fit for your project. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 182 | |
Junio C Hamano | cfa7ad0 | 2006-01-31 07:10:49 | [diff] [blame] | 183 | For example, you can choose a single person to maintain the project's |
| 184 | primary public repository. Other developers then clone this repository |
| 185 | and each work in their own clone. When they have a series of changes that |
| 186 | they're happy with, they ask the maintainer to pull from the branch |
| 187 | containing the changes. The maintainer reviews their changes and pulls |
| 188 | them into the primary repository, which other developers pull from as |
| 189 | necessary to stay coordinated. The Linux kernel and other projects use |
| 190 | variants of this model. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 191 | |
Junio C Hamano | cfa7ad0 | 2006-01-31 07:10:49 | [diff] [blame] | 192 | With a small group, developers may just pull changes from each other's |
| 193 | repositories without the need for a central maintainer. |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 194 | |
| 195 | SEE ALSO |
| 196 | -------- |
Junio C Hamano | 9e1793f | 2008-06-02 07:31:16 | [diff] [blame] | 197 | linkgit:gittutorial[7], |
| 198 | linkgit:gittutorial-2[7], |
| 199 | linkgit:gitcore-tutorial[7], |
| 200 | linkgit:gitglossary[7], |
Junio C Hamano | 446e30b | 2014-10-16 21:30:32 | [diff] [blame] | 201 | linkgit:giteveryday[7], |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 202 | link:user-manual.html[The Git User's Manual] |
| 203 | |
| 204 | GIT |
| 205 | --- |
Junio C Hamano | e89102f | 2017-02-15 23:18:15 | [diff] [blame^] | 206 | Part of the linkgit:git[1] suite |