CVS

This semester we have used just a few of the many built-in linux tools. You have used vi quite a bit. You briefly saw how make can be used to manage the compiling of applications that are built from multiple source code files. You also used bash shell scripts to perform various data manipulations.

Your final assignment involves a brief glimpse at CVS. CVS is short for "Concurrent Versioning System". CVS keeps track of various versions of files. Most usefully, CVS can help you backup your source code and help you move back in time should you need to work with an earlier version of your code.

The main component of CVS is the "respository". The respository is just like a library. You can check out your code, check in your code, allow other people to check out your code, restrict who can see what, ask questions about who has been using whichever files, have cvs notify you when someone checks out your code, etc etc etc. CVS is most useful in a group setting where several people are working on various parts of an application. In that case, the respository would be on a server.


Configuring CVS

The first step in using CVS is to build the repository. You only need to do this once. As long as you have your Winthrop linux account you will NEVER need to do these steps again. For the next several years you can check in and out files from your respository without ever repeating these steps.

Go to home directory and edit the file ".bashrc":
     cd
     vi .bashrc
Now add these two lines to the end of that file then save the changes.
     export CVSROOT=$HOME/cvsroot
     export CVSEDITOR=/usr/bin/vi
The .bashrc file is read by the bash program when it starts. In other words, the file is processed when you login. To force the system to re-read your updated .bashrc so that the changes take effect right now:
     source .bashrc

Now we need a place to hold the repository.
     mkdir cvsroot
Now we can create the respository. This next step may take several seconds to complete.
     cvs init
You now have a new directory named cvsroot that is full of stuff to manage your respository.


Adding an Item to the Respository

CVS is most useful when managing groups of source code files. But we will keep it simple and manage one file in one directory.

Create a new directory named 208lab22
     mkdir 208lab22
     cd 208lab22
Now create a new file named "myfile", put in these two lines, then save and exit vi.
     version one line one
     version one line two

Now add that file to your respository. Of course, use your name not mine.
     cvs import -m "Test Project" myfile dannelly start


Checking In and Out

Delete your file named myfile
     rm myfile
Oh no!!! You just lost that great file. No problem, it's in the respository.

To checkout a file, the command is "co" which is short for checkout.
     cvs co myfile

Note that your file came back in a new directory. CVS is set up to deal with groups of files not single files.
     cd myfile
     ls
     cat myfile

Now create a new version of your file that you can add to library. Add these two lines to the end of "myfile" then save the file.
     version two line three
     version two line four

Now check in the new version.
     cvs ci myfile
When you type the above command, cvs will start up the vi editor. Enter some comment like this then save-and-exit from vi.
     This is a minor update.
CVS saves those comments in a log that you can use to manage updates to your application.


Misc CVS Commands

CVS has a lot of commands. To see a list
     cvs help

To see a history of how your repository item has changed over time
     cvs log myfile
Information about the newest version is first, then next oldest, etc. Notice how your comments are in the log.

Edit "myfile" one more time. Add this line to the end of "myfile" then save the file.
     version three line five
Now lets ask CVS what is new in this latest version.
     cvs diff myfile

Now lets use CVS to checkout an older revision of our code. Since we already have a newer version, this will create several warning messages.
     cd ..
     cvs co -r 1.1 myfile
     cd myfile
     cat myfile
Note that the contents of myfile now show us how the file changed since version 1.1. Everything between <<<<<<<< and >>>>>>> is new.


Print your copy of myfile, write your name on it, and turn it in.