Documentation / cvs-migration.txton commit [PATCH] Make do_each_ref() follow symlinks. (a7e66ae)
   1Git for CVS users
   2=================
   3
   4Ok, so you're a CVS user. That's ok, it's a treatable condition, and the
   5first step to recovery is admitting you have a problem. The fact that
   6you are reading this file means that you may be well on that path
   7already.
   8
   9The thing about CVS is that it absolutely sucks as a source control
  10manager, and you'll thus be happy with almost anything else. Git,
  11however, may be a bit _too_ different (read: "good") for your taste, and
  12does a lot of things differently. 
  13
  14One particular suckage of CVS is very hard to work around: CVS is
  15basically a tool for tracking _file_ history, while git is a tool for
  16tracking _project_ history.  This sometimes causes problems if you are
  17used to doing very strange things in CVS, in particular if you're doing
  18things like making branches of just a subset of the project.  Git can't
  19track that, since git never tracks things on the level of an individual
  20file, only on the whole project level. 
  21
  22The good news is that most people don't do that, and in fact most sane
  23people think it's a bug in CVS that makes it tag (and check in changes)
  24one 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
  26move over to Git. 
  27
  28First off: this is not a git tutorial. See Documentation/tutorial.txt
  29for how git actually works. This is more of a random collection of
  30gotcha's and notes on converting from CVS to git.
  31
  32Second: CVS has the notion of a "repository" as opposed to the thing
  33that you're actually working in (your working directory, or your
  34"checked out tree").  Git does not have that notion at all, and all git
  35working directories _are_ the repositories.  However, you can easily
  36emulate the CVS model by having one special "global repository", which
  37people can synchronize with.  See details later, but in the meantime
  38just keep in mind that with git, every checked out working tree will
  39have a full revision control history of its own.
  40
  41
  42Importing a CVS archive
  43-----------------------
  44
  45Ok, you have an old project, and you want to at least give git a chance
  46to see how it performs. The first thing you want to do (after you've
  47gone through the git tutorial, and generally familiarized yourself with
  48how to commit stuff etc in git) is to create a git'ified version of your
  49CVS archive.
  50
  51Happily, that's very easy indeed. Git will do it for you, although git
  52will need the help of a program called "cvsps":
  53
  54        http://www.cobite.com/cvsps/
  55
  56which is not actually related to git at all, but which makes CVS usage
  57look almost sane (ie you almost certainly want to have it even if you
  58decide to stay with CVS). However, git will want at _least_ version 2.1
  59of cvsps (available at the address above), and in fact will currently
  60refuse to work with anything else.
  61
  62Once you've gotten (and installed) cvsps, you may or may not want to get
  63any more familiar with it, but make sure it is in your path. After that,
  64the magic command line is
  65
  66        git cvsimport -v -d <cvsroot> -C <destination> <module>
  67
  68which will do exactly what you'd think it does: it will create a git
  69archive of the named CVS module. The new archive will be created in the
  70subdirectory named <destination>; it'll be created if it doesn't exist.
  71Default is the local directory.
  72
  73It can take some time to actually do the conversion for a large archive
  74since it involves checking out from CVS every revision of every file,
  75and the conversion script is reasonably chatty unless you omit the '-v'
  76option, but on some not very scientific tests it averaged about twenty
  77revisions per second, so a medium-sized project should not take more
  78than a couple of minutes.  For larger projects or remote repositories,
  79the process may take longer.
  80
  81After the (initial) import is done, the CVS archive's current head
  82revision will be checked out -- thus, you can start adding your own
  83changes right away.
  84
  85The import is incremental, i.e. if you call it again next month it'll
  86fetch any CVS updates that have been happening in the meantime. The
  87cut-off is date-based, so don't change the branches that were imported
  88from CVS.
  89
  90You can merge those updates (or, in fact, a different CVS branch) into
  91your main branch:
  92
  93        git resolve HEAD origin "merge with current CVS HEAD"
  94
  95The HEAD revision from CVS is named "origin", not "HEAD", because git
  96already uses "HEAD". (If you don't like 'origin', use cvsimport's
  97'-o' option to change it.)
  98
  99
 100Emulating CVS behaviour
 101-----------------------
 102
 103
 104So, by now you are convinced you absolutely want to work with git, but
 105at the same time you absolutely have to have a central repository.
 106Step back and think again. Okay, you still need a single central
 107repository? There are several ways to go about that:
 108
 1091. Designate a person responsible to pull all branches. Make the
 110repository of this person public, and make every team member
 111pull regularly from it.
 112
 1132. Set up a public repository with read/write access for every team
 114member. Use "git pull/push" as you used "cvs update/commit".  Be
 115sure that your repository is up to date before pushing, just
 116like you used to do with "cvs commit"; your push will fail if
 117what you are pushing is not up to date.
 118
 1193. Make the repository of every team member public. It is the
 120responsibility of each single member to pull from every other
 121team member.
 122
 123
 124CVS annotate
 125------------
 126
 127So, something has gone wrong, and you don't know whom to blame, and
 128you're an ex-CVS user and used to do "cvs annotate" to see who caused
 129the breakage. You're looking for the "git annotate", and it's just
 130claiming not to find such a script. You're annoyed.
 131
 132Yes, that's right.  Core git doesn't do "annotate", although it's
 133technically possible, and there are at least two specialized scripts out
 134there that can be used to get equivalent information (see the git
 135mailing list archives for details). 
 136
 137Git has a couple of alternatives, though, that you may find sufficient
 138or even superior depending on your use.  One is called "git-whatchanged"
 139(for obvious reasons) and the other one is called "pickaxe" ("a tool for
 140the software archeologist"). 
 141
 142The "git-whatchanged" script is a truly trivial script that can give you
 143a good overview of what has changed in a file or a directory (or an
 144arbitrary list of files or directories).  The "pickaxe" support is an
 145additional layer that can be used to further specify exactly what you're
 146looking for, if you already know the specific area that changed.
 147
 148Let's step back a bit and think about the reason why you would
 149want to do "cvs annotate a-file.c" to begin with.
 150
 151You would use "cvs annotate" on a file when you have trouble
 152with a function (or even a single "if" statement in a function)
 153that happens to be defined in the file, which does not do what
 154you want it to do.  And you would want to find out why it was
 155written that way, because you are about to modify it to suit
 156your needs, and at the same time you do not want to break its
 157current callers.  For that, you are trying to find out why the
 158original author did things that way in the original context.
 159
 160Many times, it may be enough to see the commit log messages of
 161commits that touch the file in question, possibly along with the
 162patches themselves, like this:
 163
 164        $ git-whatchanged -p a-file.c
 165
 166This will show log messages and patches for each commit that
 167touches a-file.
 168
 169This, however, may not be very useful when this file has many
 170modifications that are not related to the piece of code you are
 171interested in.  You would see many log messages and patches that
 172do not have anything to do with the piece of code you are
 173interested in.  As an example, assuming that you have this piece
 174of code that you are interested in in the HEAD version:
 175
 176        if (frotz) {
 177                nitfol();
 178        }
 179
 180you would use git-rev-list and git-diff-tree like this:
 181
 182        $ git-rev-list HEAD |
 183          git-diff-tree --stdin -v -p -S'if (frotz) {
 184                nitfol();
 185        }'
 186
 187We have already talked about the "--stdin" form of git-diff-tree
 188command that reads the list of commits and compares each commit
 189with its parents.  The git-whatchanged command internally runs
 190the equivalent of the above command, and can be used like this:
 191
 192        $ git-whatchanged -p -S'if (frotz) {
 193                nitfol();
 194        }'
 195
 196When the -S option is used, git-diff-tree command outputs
 197differences between two commits only if one tree has the
 198specified string in a file and the corresponding file in the
 199other tree does not.  The above example looks for a commit that
 200has the "if" statement in it in a file, but its parent commit
 201does not have it in the same shape in the corresponding file (or
 202the other way around, where the parent has it and the commit
 203does not), and the differences between them are shown, along
 204with the commit message (thanks to the -v flag).  It does not
 205show anything for commits that do not touch this "if" statement.
 206
 207Also, in the original context, the same statement might have
 208appeared at first in a different file and later the file was
 209renamed to "a-file.c".  CVS annotate would not help you to go
 210back across such a rename, but GIT would still help you in such
 211a situation.  For that, you can give the -C flag to
 212git-diff-tree, like this:
 213
 214        $ git-whatchanged -p -C -S'if (frotz) {
 215                nitfol();
 216        }'
 217
 218When the -C flag is used, file renames and copies are followed.
 219So if the "if" statement in question happens to be in "a-file.c"
 220in the current HEAD commit, even if the file was originally
 221called "o-file.c" and then renamed in an earlier commit, or if
 222the file was created by copying an existing "o-file.c" in an
 223earlier commit, you will not lose track.  If the "if" statement
 224did not change across such a rename or copy, then the commit that
 225does rename or copy would not show in the output, and if the
 226"if" statement was modified while the file was still called
 227"o-file.c", it would find the commit that changed the statement
 228when it was in "o-file.c".
 229
 230[ BTW, the current versions of "git-diff-tree -C" is not eager
 231  enough to find copies, and it will miss the fact that a-file.c
 232  was created by copying o-file.c unless o-file.c was somehow
 233  changed in the same commit.]
 234
 235You can use the --pickaxe-all flag in addition to the -S flag.
 236This causes the differences from all the files contained in
 237those two commits, not just the differences between the files
 238that contain this changed "if" statement:
 239
 240        $ git-whatchanged -p -C -S'if (frotz) {
 241                nitfol();
 242        }' --pickaxe-all
 243
 244[ Side note.  This option is called "--pickaxe-all" because -S
 245  option is internally called "pickaxe", a tool for software
 246  archaeologists.]