A Cookbook to Get Started with CVS

RHL 2003-10-01
Unix commands are prefixed "$"; Output is prefixed with ">>".

1/ Creating the repository
--------------------------
$ mkdir /u/rhl/Repository
$ cvs -d /u/rhl/Repository init
	No; you shouldn't really try to use /u/rhl

2/ Setting your environment
---------------------------
Add these to your .bashrc file (if you only have tcsh,
the equivalent syntax is e.g. setenv CVS_RSH ssh)
$ export CVS_RSH=ssh
$ export CVSROOT=/u/rhl/Repository
$ export CVSEDITOR=emacs
       actually I use vi; but emacsclient should work too.
       If you don't set CVSEDITOR, EDITOR will be used.

If you want remote access (recommended) say something like:
$ export CVSROOT=wire7.princeton.edu:/u/rhl/Repository
	Any machine that can see "/u/rhl" should work instead of wire7


3/ Create your first module
---------------------------
I'm going to call the module "tst", but feel free to be creative.  The
module name needn't be the directory name, but it's clearer that way.
$ mkdir tst
$ cd tst
$ echo Hello World > hello
$ echo Ah, sweet death > goodbye
$ cvs import tst v1_0 v1_0_0
	you'll be popped into an editor to compose an informative message
        cvs will print:
>>   N tst/hello
>>   N tst/goodbye
>>   
>>   No conflicts created by this import
$ cd ..
$ rm -rf tst

4/ Check it out
---------------
$ cvs co tst
>>   cvs server: Updating tst
>>   U tst/goodbye
>>   U tst/hello
$ cd tst
$ ls
>>   CVS  goodbye  hello
	Ignore CVS; it's a directory with control information in it.

5/ Notice that cvs saves you from losing files
----------------------------------------------
$ rm goodbye
$ cvs update
>>   cvs server: Updating .
>>   U goodbye
$ ls
>>   CVS  goodbye  hello

6/ You can manage versions on many machines
-------------------------------------------
Check "tst" out on some other machine, or in a different directory on
the same machine

$ ssh my_laptop
	Set your environment variables as in section 2.
$ cvs co tst
>>   cvs server: Updating tst
>>   U tst/goodbye
>>   U tst/hello
$ cd tst

7/ Modify that copy
-------------------
$ emacs hello
	Make your favourite changes
$ cvs ci -m "Added an adjective" hello
>>   Checking in hello;
>>   /u/rhl/Repository/tst/hello,v  <--  hello
>>   new revision: 1.2; previous revision: 1.1
>>   done
	If you'd omitted the -m, you'd have been popped into the editor

8/ What about the other copy?
-----------------------------
Go back to the copy in section 4 and type
$ cvs -nq update
>>   U hello
	-q means quiet; -n means don't do anything.
	U means "needs to be Updated" -- but the -n means that it wasn't
$ cvs update
>>   cvs server: Updating .
>>   P hello
	The "P" means that it patched the copy of hello
$ cat hello
>>   Hello Wonderful World

9/ Who's changed what when why?
---------------------------
$ cvs log hello
>>   RCS file: /u/rhl/Repository/tst/hello,v
>>   Working file: hello
>>   head: 1.2
>>   branch:
>>   locks: strict
>>   access list:
>>   symbolic names:
>>           v1_0_0: 1.1.1.1
>>           v1_0: 1.1.1
>>   keyword substitution: kv
>>   total revisions: 3;     selected revisions: 3
>>   description:
>>   ----------------------------
>>   revision 1.2
>>   date: 2003/10/01 16:37:13;  author: rhl;  state: Exp;  lines: +1 -1
>>   Added an adjective
>>   ----------------------------
>>   revision 1.1
>>   date: 2003/10/01 16:24:43;  author: rhl;  state: Exp;
>>   branches:  1.1.1;
>>   Initial revision
>>   ----------------------------
>>   revision 1.1.1.1
>>   date: 2003/10/01 16:24:43;  author: rhl;  state: Exp;  lines: +0 -0
>>   Initial import
>>   ==========================================================================

10/ Add a new file
------------------
$ echo 'echo Version: $Name$' > version
	$Name is magic.  See below.
$ chmod 755 version
$ cvs add -m "What's my version?" version
>>   cvs server: scheduling file `version' for addition
>>   cvs server: use 'cvs commit' to add this file permanently
$ cvs ci -m "Initial revision" version
>>   RCS file: /u/rhl/Repository/tst/version,v
>>   done
>>   Checking in version;
>>   /u/rhl/Repository/tst/version,v  <--  version
>>   initial revision: 1.1
>>   done
$ rm version; cvs update version
>>   U version
$ cat version
>>   echo Version: $Name:  $
	Note that that $Name$ string was modified; this is
	magic that I'll return to in a moment
$ ./version
>>   Version: :  $
	Drat.  I forgot to quote the $Name.
$ emacs version
$ cat version
>>   echo Version: '$Name:  $'
$ cvs ci -m "quote string for the shell" version
>>   Checking in version;
>>   /u/rhl/Repository/tst/version,v  <--  version
>>   new revision: 1.2; previous revision: 1.1
>>   done

11/ Prepare to give a version away.
----------------------------------
This step should really have been done with the import, but I didn't
want to frighten you then.

$ cvs co CVSROOT/modules
>>   U CVSROOT/modules
$ echo "tst   tst" >> CVSROOT/modules
$ cvs ci -m "Added module tst" !$
>>   cvs ci -m "Added module tst" CVSROOT/modules
>>   Checking in CVSROOT/modules;
>>   /u/rhl/Repository/CVSROOT/modules,v  <--  modules
>>   new revision: 1.2; previous revision: 1.1
>>   done
>>   cvs server: Rebuilding administrative file database
$ cvs -Q release -d CVSROOT
	I just added a definition of module "tst".  I shouldn't need to do
	this, but I do.  Sorry.  This should be done once for each module,
	as you create it.  If you forget you'll be OK.

	First I checked out the magic file "modules" (cvs co);
	then modified it; then checked it back in (cvs ci); then
	forgot that I'd checked it out (cvs release).

12/ Give away a known version of my module
------------------------------------------
$ cvs tag v1_1
>>   cvs server: Tagging .
>>   T goodbye
>>   T hello
>>   T version
$ mkdir ~/TMP; cd ~/TMP
$ cvs export -r v1_1 tst
>>   U tst/goodbye
>>   U tst/hello
>>   U tst/version
$ cd tst
$ ls
>>   goodbye  hello  version
	 Note that there's no CVS directory.
$ ./version
>>   Version: $Name: v1_1 $
	It knows that you asked for version v1_1.

13/ Where's the manual?
-----------------------
	There a slightly out-of-date version in
	http://www.astro.princeton.edu/~rhl/cvs/cvs.html