Use CVS to manage your programs

Source: Internet
Author: User
Tags ftp site
Article title: use CVS to manage your own programs. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Every programmer may have had this experience: he made some modifications to the program. a few days later, we may find that the last modification caused other conflicts, even compilation fails, but it is difficult to find out where we just made the changes. In general, we always want to keep a complete record of the next program development process and record every improvement and adjustment of this program. Maybe we can use the backup method to solve this problem, so we create a backup directory and package our source program on a regular or irregular basis, until one day the entire hard disk is full of these files. This is an exaggeration of course, but the inconvenience this mechanism brings to us is obvious. Furthermore, it is difficult to develop a software product by one person. It may contain several, dozens or even hundreds of programmers for collaborative development. how can we manage the source code? The solution is to use CVS. CVS-Concurrent Versions System (Concurrent version management System) is a version control management System, which is currently the most widely used System. From gftp to gtk to KDE, you can see trace of it in almost every source code of the free software you are familiar with (we will know below, its Trace refers to a subdirectory called cvs ). Similarly, you can see the CVS system in almost every Linux release version. It can be said that if CVS is lost, many existing software that can be collaborated and freely developed by many people will be slowed down to some extent. What features does CVS have to make it so powerful?
  
   1. what can CVS do?
As mentioned above, CVS is a version management system, which can retain the information of each version in the software development process, including who, when, what changes were made, and why such changes were made. This function is very similar to the version management System (RFS) and SCCS (Source Code Control System) that were popular in Linux and Unix. However, CVS is far from only available. Its biggest characteristic is its concurrency, that is, it supports the development of distributed projects. Today, when the Internet is sweeping all over the world, this function is too important. From the development of an OA system in an office to the development of a new version of KDE by the KDE team on the Internet, CVS can all show their skills. After a programmer develops a new version of his/her module, he quickly uses CVS to share his/her latest achievements with every member of the development team. Even CVS allows multiple programmers to modify the same source program file at the same time through a specific mechanism. In addition, CVS's enhanced directory structure and good processing of binary files make it far better than other version management systems. Finally, it must be mentioned that CVS is developed based on RCS.
  
   2. how to get CVS?
CVS is included in almost all Linux release versions, such as RedHat, Turbo Linux, Slackware, domestic red flag, and Xteam Linux. You can try to run the cvs command. In most cases, a pile of information starting with Usage: cvs appears, prompting you how to use cvs, this means that you already have CVS on your machine, but unfortunately it has never been discovered and used by you. If you are not lucky, you will see a prompt like cvs: Command not found. which means that your machine has not installed CVS. You have two options. First, find your Linux installation disk and install CVS from there. For example, in a Linux installation using RPM (except for Slackware in several release versions described above), find cvs ***. run the rpm command to install the tool. The second method is to go to the source code of some site cvs and install it following the instructions provided in it. For more information, visit the site http://www.icic.com/#http://www.loria.fr /~ Molli/cvs-index.html.
  
   3. basic usage of CVS
In this section, we will learn some basic methods to use CVS. Now we assume that CVS has been installed and we plan to use it to manage a software we are developing. the software name is netants, which is stored in a directory named netants on the hard disk, the file netants is currently in use. c. netants. h. http. c. http. h and Makefile. We didn't develop the software in collaboration with others, nor did we use the Internet or Intranet to develop the software. Perhaps, it is just a part-time work of its own, trying to write a better download tool than the network Ant in Windows.
  
3.1 initialize CVS
  
The first command we need to use is cvs init, which is used to initialize the CVS system. As we can see, all CVS commands start with cvs, followed by commands, parameters, and some options. The main purpose of the CVS system initialization is to create a source code repository (repository) used by CVS ). You must specify the directory in which the source code repository is created. You can specify a directory in two ways. First, use "-d <目录路径> -D/usr/local/cvsroot. Another more convenient method is to set an environment variable named CVSROOT in shell. You can use the setenv command to set csh or tcsh. add the following line to the file. csh rc or file. tcshrc:
Setenv CVSROOT/usr/local/cvsroot
To use sh or bash, add the following two lines to the file. profile or file. bashrc:
CVSROOT =/usr/local/cvsroot
Export CVSROOT
After the environment variable CVSROOT is set, run the command cvs init. CVS will create some files needed under the specified directory. in the future, we will use any projects managed by CVS, CVS will be stored in this directory. However, you must never try to modify the files in this directory. This directory is managed by CVS itself. rash changes may lead to loss of some or all of your source code or other resources managed by CVS.
  
3.2 import the project to CVS
  
After initialization, we must use CVS to manage our program network Ant Financial. Step 1: submit the project to CVS for management. Use the following CVS import command to import the source program to the source code repository of CVS:
Cd netants
Cvs import-m "start my project: Netants" netants yoyo start
This command looks complicated and needs to be explained. Import is the cvs import command. by default, it cyclically imports all files (including subdirectories) in the current directory into the source code library (that is, the directory specified by CVSROOT. -M "start my project: Netants" tells CVS about this step. This is mandatory by CVS. if you do not use this-m "string" option, CVS will pop up a text editor (if you do not specify this option, in Linux, it is usually vi, but in Windows it is Notepad), let you enter some instructions to give up. Netants is the path name of the project stored by CVS, that is, CVS will create a $ CVSROOT/netants directory and store the files of this project under this directory. of course, it is not an intact storage, and CVS will do some processing. The last two strings have two tags, which are useless now, but they are also required by CVS, so we add these two parameters. When executing this command, CVS automatically sets all file versions to 1.1, which is the lowest version it considers. The following information is displayed after the preceding command is executed: N netants/netants. c N netants/http. c N netants/http. h N netants/netants. h N netants/Makefile
  
No conflicts created by this import N indicates that New, CVS successfully loads these files, and No conflict is found.
The above Command is a little longer and tedious. believe me, CVS is not always like this. this "tedious" is totally negligible as it brings us convenience.
  
3.3 export a project from CVS
  
Now, we have handed over our netants project to CVS for management. now, we can delete the original netants directory that stores our code (for security, of course, you may need to make another backup and hope it is the last one ). We are going to do the development work. create a directory and call it worktmp. Run the command cvs checkout netants in this directory. we will see the following information: cvs checkout: Updating netants U netants/Makefile U netants/http. c U netants/http. h U netants/netants. c U netants/netants. h
CVS creates a directory named netants in the current directory. all our original code files appear in this directory, and there is also a directory named CVS. The directory CVS stores some text files, recording the location of CVSROOT, the directory corresponding to the source code library of this project, and other information.
  
3.4 save the modification to CVS
  
Now, we start to work hard and excellent programming. After dozens of minutes, hours, or even days of work, we have made major changes to the original code, and it is coming to an end. We submit the modified content to CVS, so we need to execute the command
Cvs commit-m "Made some useful changes on some files"
At this time, we will see some prompts provided by CVS, which scans and compares the existing files in this directory and the original files saved in the source code library, the modified file will be updated with the new version: 1.2. The-m parameter, as mentioned earlier, is used to enable a text editor to input the parameter. If we modify only one or two files, we can attach the file name at the end of the above command, so that CVS will only compare and update the specified file. Note that, unlike self-backup, CVS only saves the differences between different versions, and does not completely save each version. Do you think CVS is useful now.
  
3.5 add files to the project
  
One day, we began to consider adding the file download function from the ftp site to our network Ant, so we need to add two files in the original project: ftp. c and ftp. h. First, we create, edit, modify, and generate these two files in the working directory, and then add them using the add command.
Cvs add ftp. c ftp. h
At this time, the file is not actually added, but it is equivalent to "registration". to make this process take effect, we still need to use the commit command:
Cvs commit ftp. c ftp. h-m "Add two files: ftp. c and ftp. h"
At this point, CVS will add these two files to the project, and their versions are all the initial 1.1.
  
3.6 delete files from the project
  
Apart from adding a file, we may need to delete it sometimes. for example, we found that the file netants. h is useless. Therefore, execute the following commands to complete the deletion:
Rm netants. h
Cvs remove netants. h
Cvs commit netants. h-m "Delete a file ."
Note that CVS only deletes the current version of netants. h, and its previous version still exists, unless it happens to have only version 1.1.
  
3.7 set a specific version number
  
After a period of work, the program has begun to take shape and formed a stable version.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.