Article

Harness the Power of CVS for Your Site

Page: 1 2 3 4

In the meantime, Glenplake, being one of those experienced Linux types (as well as a Photoshop pro -- his talents were beyond compare!), logged into his Linux Web server and quickly set up the environment for use with their new CVS tree.

Most common Linux distributions already have ssh and the cvs client installed (Glenplake's certainly did) so you can set up the environment as we did in Windows, using the following commands:

export CVS_RSH=ssh    
export CVSROOT=glenplake@cvs.theproject.sourceforge.net:/    
cvsroot/the_project

Glenplake, being even more clever than that, edited the file .bash_profile in his Linux home directory and added:

CVS_RSH=ssh    
CVSROOT=glenplake@cvs.theproject.sourceforge.net:/cvsroot/the_project    
export CVS_RSH    
export CVSROOT

This meant that every time he logged in, he would have the environment variables set correctly and not need to re-type them.

Now, moving to the Web root directory on his server with:

cd /home/glenplake/www

...he renamed the version of the code he had installed there:

mv the_project the_project_old

Next, he grabbed the latest version from the repository with:

cvs -z3 co the_project

Success! Glenplake now had a working copy of the repository.

He swiftly copied the work he'd done from the old directory to the new working copy:

cp the_project_old/updated_file.php the_project/    
   
cp the_project_old/new_image.gif the_project/

Here's what those commands did:

  1. Copied one of HarryF's files that Glenplake had updated to the working directory

  2. Copies a new image Glenplake had created to the working directory

Then he moved into the working directory:

cd /home/glenplake/www/the_project

...and introduced his work to the CVS repository. For the file he updated he used:

cvs commit -m "Fixed some bugs" updated_file.php

...to commit the file to the repository. He used the -m "Fixed some bugs" to add a log message to updated_file.php's revision history, so that later, both developers would be able to see what had happened to the file.

Then, for the new file he created, Glenplake typed:

cvs add -kb new_image.gif    
cvs commit -m "The project logo" new_image.gif

...to add the new image to the repository. "cvs add" tells CVS to schedule this file to be added to the repository next time a commit is performed. The "-kb" tells CVS that the file is binary, and must be handled with care. "cvs commit -m "The project logo" new_image.gif" actually commits the new image to the repository, with the log message "The project logo".

On Windows, Glenplake could also have happily performed the same cvs commands using the "cvs.exe" client.

Now that he was finished, Glenplake went out to steal some bagels from his local bakery.

Meanwhile, in a land far, far away, HarryF returned home and got back to work on the_project.

Because he'd been paying attention to the documentation, he knew it was a good idea to begin with a "cvs update", to check that he had the latest version of the repository. So he typed:

cvs update

...and CVS responded with:

U the_project/updated_file.php    
U the_project/new_image.gif

CVS checked to see if HarryF had the latest version of the repository. It then found the updates Glenplake had made and downloaded them into HarryF's working copy, giving him the latest files to work with.

And so Glenplake and HarryF carried on, exceeding all their private expectations and completing a project of quite some magnitude.

Wrapping Up

If you'll forgive the poor prose, this last example should give you an idea of how CVS works, particularly when you're collaborating with someone else. This is only a simple demonstration of what CVS is capable of and I'm sure there's no need to tell you it can do loads more for you.

For starters, we haven't really looked at how CVS tracks revisions and how you can view the logs, view diffs (differences between one revision and another), restore older revisions of your work, resolve conflicts, and a whole host of other things. But with what you now know, you have enough to get started with CVS. As you delve further into it, you'll find making sense of the documentation a lot easier, and quickly pick up what you need.

Getting Help

Perhaps the best place to start is the CVS Book which -- though long -- takes time to explain concepts clearly. If you just take a quick glance at the contents page, you'll get an idea of some of the more advanced things you can do with CVS. Alternatively, you might like to try CVS Version Control for Web Site Projects which covers less ground, but is geared more to Web builders like us. The "official" documentation can be found either at http://www.cvshome.org or here. And of course, if you don't like any of these resources, a quick search on Google will find many alternative explanations, tutorials and guides. You are most definitely not alone with CVS.

CVS Server for Windows

As we mentioned at the start of this article, CVS isn't just for the *Nix types. It's widely used and, as you've already begun to see, well supported. It's also popular in many companies where it's typically used in software development. Without doubt, any skills you can develop with CVS are good news for your resume.

So, Windows users, wander over to http://www.cvsnt.org/ and grab yourself a copy. You'll find alternative step by step installation guides here and here. The CVSNT server is confirmed as being able to run on Windows NT4 Server/Workstation with Service Pack 6, Windows 2000 Server/Professional and Windows XP-Pro. There's also a cut down version able to run on Windows 95/98, so all in all, you should be able to get a server up somewhere.

Viewing CVS Online

Finally, there are also Web-based CVS viewers available that allow you to browse your CVS tree online -- very nice for catching up on what the tree contains, and what changes have been made. Three examples are Chora, written in PHP, ViewCVS, written in Python and cvsweb, written in Perl.

So, go forth boldly into the brave new world of CVS, and may all your revisions become releases!

The author would like to thank to Dan, who was subjected to numerous bizarre experiments in the writing this of article.

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links

Rate This Article

  • 1
    Poor
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
    Great

Comment on This Article

Have something to say?

Post A Comment

You need to be a member of the SitePoint Forums to comment on this post. Sign Up

Already a member? Post using your SitePoint Forums account: