########## CVS - the command line tool ########## -=Getting ready for using CVS=- CVS can be used on NTNU's login servers, linuxlogin.stud.ntnu.no (or just login.stud.ntnu.no). The first thing that must be done when you wish to use CVS is to create a so-called *CVS root*. It is under this that all data will be stored. Let's say you wish to create a CVS root in a folder called "cvs", located in your home area. You start by creating the folder: gaupe:~$ mkdir cvs You can then create the CVS root in this folder with the following command: gaupe:~$ cvs -d ~grip/cvs init The argument "-d ~grip/cvs" indicates where the CVS root is located (substitute "grip" with your own user name). If you wish to not have to write this argument in all commands before the project is created, you may enter: gaupe:~$ export CVSROOT=~grip/cvs This will create an environment varable, "CVSROOT", with the path of the CVS root as it's value. -=Creating a project=- Everything is now ready to start creating projects for storing in CVS. Let's say there is a folder called "java", with a programming project in, for which you wish to use CVS. You then enter the "java" folder and create the CVS project with all the files and subfolders: gaupe:~$ cd java gaupe:~/java$ cvs import -m "A little java project" javaproject example start N javaproject/a_file.java N javaproject/testfile.java No conflicts created by this import You should get a response similar to the one above, which indicates that the listed files have been added in a so-called CVS repository for the project, which is a place under the CVS root where the project data is stored. The name of the repository is, in the example above, specified to be "javaproject". If you wish to, you may now delete the entire "java" folder, as everything is stored in CVS. -=Working with the project=- This is all good, but we wish to work with the files, and make changes, create new and delete old files. What you need to do is to go to a folder where you wish to place a working copy of the files, and enter: gaupe:~$ cvs checkout javaproject cvs checkout: Updating javaproject U javaproject/a_file.java U javaproject/testfile.java A copy of the java project will now appear in the folder "javaproject". This is a local copy, with which you may do whatever you want. You may change the files, delete files, create new files etc. The nice thing is that this does not change what is in the CVS repository at all. When you feel that you have done something useful, like having made some changes to "testfile.java", you may *update the repository* with the changes, by entering: gaupe:~/javaproject$ cvs commit -m "Made a new print method" testfile.java Checking in testfile.java; /home/homej/gr/grip/cvs/javaproject/testfile.java,v -- testfile.java new revision: 1.2; previous revision: 1.1 done The file has now been stored in the repository with the comment in quotation marks, but has been given a new version number. Thereby, the old version is not overwritten, but can be retrieved again if you decide to revert back to it. To *compare a local file with the one in the repository*, you may enter: gaupe:~/javaproject$ cvs status a_file.java =================================================================== File: a_file.java Status: Locally Modified Working revision: 1.1.1.1 Tue Jan 28 19:30:38 2003 Repository revision: 1.1.1.1 /home/homej/gr/grip/cvs/javaproject/a_file.java,v Sticky Tag: (none) Sticky Date: (none) Sticky Options: (none) You can then see if the version you are working with is up to date, or if it is older or has been changed compared to the one in the repository. In the status field above, you can see that this file has been changed since it was last synchronized with the repository. If you wish to *update your local copy*, you may enter: gaupe:~/javaproject$ cvs update a_file.java M a_file.java To *add a new file* that you have created, you have to enter two commands: gaupe:~/javaproject$ cvs add another_file.java cvs add: scheduling file `another_file.java' for addition cvs add: use 'cvs commit' to add this file permanently gaupe:~/javaproject$ cvs commit -m "Another file" another_file.java RCS file: /home/homej/gr/grip/cvs/javaproject/another_file.java,v done Checking in another_file.java; /home/homej/gr/grip/cvs/javaproject/another_file.java,v -- another_file.java initial revision: 1.1 done You may *remove a file* from the repository by entering: gaupe:~/javaproject$ cvs remove another_file.java cvs remove: scheduling `another_file.java' for removal cvs remove: use 'cvs commit' to remove this file permanently gaupe:~/javaprosjekt$ cvs commit -m "Removed a useless file" another_file.java Removing another_file.java; /home/homej/gr/grip/cvs/javaproject/another_file.java,v -- another_file.java new revision: delete; previous revision: 1.1 done -=Reviewing the log of a file=- For a detailed overview over the history of a file, you may enter: gaupe:~/javaproject$ cvs log testfile.java RCS file: /home/homej/gr/grip/cvs/javaproject/testfile.java,v Working file: testfile.java head: 1.2 branch: locks: strict access list: symbolic names: start: 1.1.1.1 eksempel: 1.1.1 keyword substitution: kv total revisions: 3; selected revisions: 3 description: ---------------------------- revision 1.2 date: 2003/01/28 19:45:54; author: grip; state: Exp; lines: +1 -1 Made a new print method ---------------------------- revision 1.1 date: 2003/01/28 19:45:20; author: grip; state: Exp; branches: 1.1.1; Initial revision ---------------------------- revision 1.1.1.1 date: 2003/01/28 19:45:20; author: grip; state: Exp; lines: +0 -0 A little java project ============================================================================= -=CVS with several users=- If you use CVS in a project with several users, each user works on his or her own, local copy of the project, but up against the same CVS repository. Therefore, everyone involved needs the correct access to it. If you have a common area that can be used for this purpose, it is natural to create the CVS root here. If you, for instance, have been given the area "/home/prosjekt/sif8005/sif8005_204", you should exchange the commands in the section /Getting ready for CVS/ with the following: gaupe:~$ cd /home/prosjekt/sif8005/sif8005_204 gaupe:/home/prosjekt/sif8005/sif8005_204$ mkdir cvs gaupe:/home/prosjekt/sif8005/sif8005_204$ export CVSROOT=/home/prosjekt/sif8005/sif8005_204/cvs gaupe:/home/prosjekt/sif8005/sif8005_204$ cvs init Note that, by setting the environment variable first, you may skip the extra argument to "cvs init". Also note that everyone involved needs to set this environment variable before they check out their local copy (see the section /Working with the project/). You must also make sure to set the permissions on the CVS repository such that everyone involved has access. If there is a particular group created for the project, for instance "prog204", you must make sure that the repository is owned by this group, and that the group has the right permissions. After the project has been created (again we assume it has the name "javaproject"), the following commands will to the trick: gaupe:/home/prosjekt/sif8005/sif8005_204$ cd cvs gaupe:/home/prosjekt/sif8005/sif8005_204/cvs$ chgrp -R prog204 javaproject gaupe:/home/prosjekt/sif8005/sif8005_204/cvs$ chmod -R g+r javaproject gaupe:/home/prosjekt/sif8005/sif8005_204/cvs$ find javaproject -depth -type d -exec chmod g+wx {} \; What happens here is that the files are made to belong to the group "prog204". Then the group is given read permission on all the files and subfolders in the repository, and finally the group is given write permission on all the folders in the repository. When it comes to the write permission, it is the folders that are essential, not the files themselves. -=Other functionality=- The functionality of CVS goes far beyond what is presented here. For help on the usage of a certain command, type "cvs -H command", where command is the command you wish to get help on. You can also get an introduction and help by typing "man cvs"