< Zurück | Inhalt | Weiter >

8.2.5 Merges

When you commit changes, a new version of each changed file is now part of the repository. If someone else commits changes, that person’s changes are now part of the repository as well. But those changes (unlike your own local changes) are yet to appear in your own local copy of the files, that is your sandbox.

The following CVS command will bring your files up to date with all the changes made since you checked out your copy (or last did an update):

$ cvs update

With that command all the files from the current working directory on down will be updated with the most recent versions of the files from the repository—and not just updated: changes that you have made in your local files will be preserved and merged with the new version of the files.

Here’s what a successful merge looks like:

$ cvs update Account.java

cvs server: Updating Account.java M Account.java

RCS file: /usr/local/srcbank/JavaAppDevLinux/Account.java,v retrieving revision 1.17

retrieving revision 1.18

Merging differences between 1.17 and 1.18 into Account.java M Account.java


Remember our scenario earlier in the chapter? Our two programmers, Ti and Kwan, have each modified the same file. If all Kwan changed was adding a new method, it would merge just fine. But what if they both made changes in the same region of the source file? Well, the first one to check in his changes will be fine. His commit will succeed. But the second person to try to commit changes to the file will find that CVS will report an error:

$ cvs commit Account.java

cvs server: Up-to-date check failed for `Account.java' cvs [server aborted]: correct above errors first!

cvs commit: saving log message in /tmp/cvsQ9rk01

Now, attempting to update will put both versions in your local file, marked up by certain character strings to highlight and separate the sections. It is up to the programmer to resolve those conflicts and commit the source once again.

Here’s an example of how a conflict might look in a source file:

<<<<< ver. 1.7

for (i=0; i<20; i++) { myData.callSomething(dollars, time);



while (i<20) { myData.callOtherwise(dollars*(i++), time/60);



In such a case, the programmer must decide which changes to keep, or how to combine them. After editing the file and removing the dividing lines (i.e., <<<<<, =====, and >>>>>), recompiling and probably a bit of testing, too, the programmer can now do a cvs commit to incorporate his changes in the repository.