Use apt-get or yum to install CVS.
~]# yum install cvs
Initialize CVS. This will create a directory named CVSROOT in the /var/cvs directory.
~]# cvs -d /var/cvs init
How to use CVS
CVS is a version control system, where different versions of a file will be stored in CVS. The general flow of working with files in CVS is:
- Check out, to get the latest version of the files in CVS
- Add a new file or update an existing file in CVS
- Check the new or updated file into CVS, which makes a new version of the file in CVS
Check out – to get the latest version of files in CVS
Move into your CVS home directory.
~]# cd /var/cvs
Check out (co) the current CVS repository. This command ensure you are working with the latest version of each file in CVS. This command will produce lines beginning with C (checkout) or U (update) followed by the files that are being checked out.
~]# cvs checkout -P /var/cvs cvs checkout: Updating /var/cvs U /var/cvs/file1.txt C /var/cvs/file2.txt U /var/cvs/file3.txt
The -q (quiet) and -Q (very quiet) options can be used to suppress output, which is usually preferred when doing a checkout in a script.
~]# cvs -q checkout -P /var/cvs ~]# cvs -Q checkout -P /var/cvs
If you have a large number of files in CVS, it can take a while to check out the entire CVS repository. You can check out only a certain file or directory in CVS, to reduce the time it takes to check out.
~]# cvs checkout -P /var/cvs/path/to/directory ~]# cvs checkout -P /var/cvs/path/to/file
Add a new file to CVS
The add option can be used to add a new file to CVS. First, you will want to create a new file in CVS. In this example, a new shell script is created.
~]# cd /var/cvs ~]# touch myScript.sh
Add the new file.
~]# cvs add myScript.sh
Commit the new file.
~]# cvs commit myScript.sh
When committing, your default text editor will prompt you to provide describe what is being committed. The -m option can be used to describe what is being committed without using your default text editor. This is very useful when committing inside of a script.
~]# cvs commit -m "Example" myScript.sh
View status / view log
View the revision number of the new file (it should be 1.0).
~]# cvs status myScript.sh ===================================================================== File: myScript.sh Status: Up-to-date Working revision 1.0 Mon Jan 01 12:34:56 2017 Repository revisions: 1.0 /var/cvs/myScript.sh Sticky Tag: (none) Sticky Date: (none) Sticky Options: (none)
The log command can be used to view each revision, and the summary of the changes made during each revision.
~]# cvs log <file name> total revisions: 2; selected revisions: 2 description: ----------------------------- revision 1.2 date: 2018/02/28 07:50:56; author: Wenyd; state: Exp; lines: +131 -188 Summary of next revision ----------------------------- revision 1.1 date: 2018/02/15 05:06:27; author: Jeremy; state: Exp; Summary of first revision ======================================================
Update a file already in CVS
Before updating a file in CVS, ensure you have checked out, to get the latest version of the files in CVS.
Make a change to a file in CVS. Then, check the file in, which creates a new version of the file in CVS.
~]# cvs ci <file name> new revision: 1.1; previous revision: 1.2 done
Commit the file.
~]# cvs commit <file name>
View the revision number of the new file.
~]# cvs status myScript.sh ===================================================================== File: myScript.sh Status: Up-to-date Working revision 1.1 Mon Jan 01 12:34:56 2017 Repository revisions: 1.1 /path/to/<file name> Sticky Tag: (none) Sticky Date: (none) Sticky Options: (none)
Removing files from CVS
The remove option can be used to remove file from CVS. Remove the file.
~]# rm <file name>
Remove the file from CVS.
~]# cvs remove <file name>
Commit the removal.
~]# cvs commit <file name>
Spot differences between revisions
The cvs diff command can be used to spot differences between revisions.
cvs diff -r <old_version> -r <new_version> example.txt