home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


  Previous section   Next section

2.6 Committing Changes

Once you've checked out project files into a sandbox, you can edit those files with your preferred editor. Changes are not synchronized with the repository until you run the cvs commit command. This command is best run from the root directory of your sandbox, and it must be run from within the sandbox.

Commit to the repository frequently. Rules of thumb for when to commit include "every time the code compiles cleanly" and "every day before lunch and before you leave."

In programming projects with several developers, try to avoid committing code that doesn't compile.

When you commit, CVS examines each directory and subdirectory below the current working directory. It searches for files that it is tracking that have changed, and commits all changes to the repository. See Example 2-12 for an example of committing files. Remember, the repository path is stored in the sandbox, so you don't need to specify the path explicitly in your cvs commit command.

Example 2-12. Committing files
$ cd ~/cvs/example
$ cvs commit
cvs commit: Examining .

If your repository is not on the local machine and your repository server doesn't have your SSH public key, CVS will ask for a password for the remote machine. If the server has the public key, your SSH client can use the private key to authenticate you.

If any files have been changed, CVS opens an editor to allow you to record a change message. By default, the editor is vi, just as when importing a project. Chapter 3 gives instructions on changing your editor.

I strongly recommend meaningful change notes. If you're trying to do a rollback and all you have are messages that say "fixed a few bugs," you won't know which revision to roll back to. See Example 2-13 for an example of a good change note.

Example 2-13. Enter a commit message
CVS:------------------------------------------------------------------
CVS: Enter Log.  Lines beginning with 'CVS:' are removed automatically
Corrected bug #35. 'hello' was misspelled as 'helo'.
CVS: 
CVS: Committing in .
CVS: 
CVS: Modified Files:
CVS:  file1 
CVS:------------------------------------------------------------------

After you exit the editor, CVS completes the commit, displaying messages similar to those in Example 2-14.

Example 2-14. Completing the commit
Checking in file1;
/var/lib/cvsroot/example/file1,v  <--  file1
new revision: 1.2; previous revision: 1.1
done

If a revision in the repository is more recent than the revision the sandbox was based on, cvs commit fails. Use the cvs update command to merge the changed files; then run cvs commit again. Example 2-15 shows the response to a failed commit.

Example 2-15. Failed commit
cvs server: Up-to-date check failed for 'file2'
cvs [server aborted]: correct above errors first!
cvs commit: saving log message in /tmp/cvst7onmJ

  Previous section   Next section
Top