oreilly.comSafari Books Online.Conferences.


Introduction to CVS
Pages: 1, 2

When Changes Conflict: Merging Files

If CVS can't merge a modified file successfully with the copy in the repository, it announces the conflict in the output of cvs update. The original file is stored in .#file.version in the file's working directory, and the results of the merge are stored as the original filename.

cvs/example$ cvs update's password: 
cvs server: Updating .
RCS file: /home/cvs/example/sample.c,v
retrieving revision 1.3
retrieving revision 1.4
Merging differences between 1.3 and 1.4 into sample.c 
rcsmerge: warning: conflicts during merge
cvs server: conflicts found in sample.c 
C sample.c 

CVS writes the merge with the conflicting lines surrounded by CVS tags. CVS can't automatically merge conflicts where the same line is changed in both versions of a file.

<<<<<<< sample.c 
Deliberately creating a conflict.
Let's make a conflict.
>>>>>>> 1.4

Making Changes: cvs commit

Once your files are checked out, edit them and compile them normally. Apply the updates to the repository with cvs commit. This command needs to be run from higher in the hierarchy than all the files you have changed -- you can run it from the base of your working copy.

You can also cvs commit filename, which will commit a single file or recursively commit a directory.

Different project teams have different opinions on how often to cvs commit. Good rules of thumb include "every time you have a clean compile," and "every day before lunch and before you leave."

cvs/example$ cvs commit
cvs commit: Examining .
cvs commit: Examining src's password:

CVS examines each directory and subdirectory below the current working directory. Any files that CVS knows about will be checked for changes. If your cvs repository is not on the local machine, CVS will ask for a password for the remote machine.

CVS then opens whichever editor is the default in your environment -- based on the $CVSEDITOR or $EDITOR environment variables. Add change-notes for the appropriate files.

CVS: Enter Log.  Lines beginning with 'CVS:' are removed automatically
CVS: Committing in .
CVS: Modified Files:
CVS:  example/src/sample.h example/src/sample.c 

I strongly recommend meaningful change-notes -- if you're trying to do a rollback and all you have are messages which say "fixed a few bugs," you'll not know which version to roll back to without using cvs diff.

If there is a potential conflict, cvs commit fails. Correct this by running a cvs update on the repository -- CVS will attempt to merge the files, and will ask for human help if it cannot do this without losing data.

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

Making New Files: cvs add

Files CVS doesn't know what to do with are reported with a question mark after the commit process and during a cvs update. They need to be added to the repository before CVS will recognize them.

Use cvs add filename to mark a new file for inclusion. CVS doesn't put the file in the repository until you do a cvs commit.

Directories are added with the same command. Files within a directory can't be added until the directory is added.

Removing Files: cvs remove

To mark a file for removal from the working copies, use cvs remove filename. Before CVS will remove a file from the repository, you have to actually delete it from the filesystem. CVS doesn't actually remove the file entirely, it puts it in a special subdirectory in the repository called Attic.

Directories Don't Remove

CVS does not remove directories -- it would break the change tracking. Directories can be removed by changing the repository -- this is discussed in "CVS Administration."

Final Words

CVS is useful as a tool for concurrent development, maintaining file histories, and providing a central database for files of any sort. It's well worth looking into and playing with.

Further Reading

  • man cvs
  • man 5 cvs
  • info cvs has a good section on "what CVS is" and "what CVS is not." It's also a useful expansion on the manual. The "Repository" section discusses protocols.
  • From the Big Scary Daemons column: BSD Tricks: CVS
  • Sourceforge has several articles on CVS. See sections 6 and 7 on the Sourceforge Site Docs page.

Jennifer Vesperman is the author of Essential CVS. She writes for the O'Reilly Network, the Linux Documentation Project, and occasionally Linux.Com.

Return to the Linux DevCenter.

Linux Online Certification

Linux/Unix System Administration Certificate Series
Linux/Unix System Administration Certificate Series — This course series targets both beginning and intermediate Linux/Unix users who want to acquire advanced system administration skills, and to back those skills up with a Certificate from the University of Illinois Office of Continuing Education.

Enroll today!

Linux Resources
  • Linux Online
  • The Linux FAQ
  • Linux Kernel Archives
  • Kernel Traffic

  • Sponsored by: