CVS simple tutorial
V2.1 Copyright Notice: This document follows the FDL copyright release, please refer to: http://www.fsf.org/copyleft/fdl.html
He Weiping
CVS is an abbreviation for the Concurrent Version System for version management. If you have participated in the projects that have collaborated with many people, everyone must have such a painful experience: Since many people have modified the same document, their own hard-modified procedures are completely deleted by others. Also, if your software / program has released three versions, at this time, the user needs you to modify the second version, maybe you will cry because only the latest version is kept. There is also some modifications to the program, but the modifications are very few, you only want to send a different version of the different versions to the distant colleagues, which can be exempted from the mailbox is not big enough, the network speed is too slow. . In order to solve problems like this, and such as generating patch files, historical version modifications, a bunch of hackers (commendation) has developed CVS based on the Mature SCCS and RCS in the original UNIX system. (SCCS: Source Code Control System, RCS: Revision Control System)
The basic work idea of CVS is this: Create a repository on one server, and many source processes of many different items can be stored in the warehouse. The source program is managed by the warehouse administrator. In this way, it seems that only one person is like a file. Avoid conflicts. Each user first uses the warehouse to download the project file in the warehouse to the local. Any modification of the user is first conducted locally, then submitted by the CVS command and is unified by the CVS warehouse administrator. This will do tracking file changes, conflict control, and more.
Since CVS is a typical software software, it is also divided into two parts: the server side and the client. However, most CVS software combines them two.
In combination with documents and some online resources, I write a very simple "quick" textbook. hope its good for U.S. Here is my steps and practices: Premise:
ROOT permissions; CVS software, find related rpm, tgz, deb and other packages, or to http://www.cvshome.org/cvs/dev/code download the original program compilation installation, here I don't prepare to introduce it Please refer to the CVS own document installation. I use SLACKWARE TGZ package, the installed command is #installpkg cvs * .tgz other packages, please refer to the command of the corresponding package management tool. A certain system resource, there must be a certain amount of memory (32M can work very well), to have a certain disk space to see your size and how much. Set up the CVS server:
Establish a cvsroot directory because here involves the user's permission issues read and written in CVSROOT, so a relatively simple method is to create a group, then build an account belonging to the group, and the user who has read and write will Belong to this group. Suppose we built a group called CVS, the username is CVSROOT. The order and user's order is as follows
#groupadd cvs
#Adduser CvsRoot Home Directory in / Home / CvsRoot (according to your own system adjustment), modify / home / cvsroot (cvsroot) permissions with CVSROOT (CVSROOT) permissions:
$ chmod 771. (or 770 should also)
Note: This part of the work is done according to the documentation, there must be no trial, I will do it in the later version of the tutorial after doing the test. If you have this experience, please give me, thank you.
Establish a CVS warehouse (still cvsroot users), with the following command:
$ cvs -d / home / cvsroot init
Log in as root, modify / Etc/inetd.conf (using Xinetd's system without this file) and / etc / services,
If you use inetd, add: Cvsserver Stream TCP NOWAIT ROOT / USR / BIN / CVS CVS -F - Allow-root = / Home / CVSROOT PSERVER
Note: The above line is a single line, / usr / bin / cvs should be your CVS version of the command path, please adjust according to your system. / Home / CVSROOT is the path to the cvsroot you created, and also adjust it according to the contents of the part of the directory above.
If you are using the XINETD system, you need to create a file CVSPServer in the /etc/xinetd.d/ directory (this name can be defined by yourself), the content is as follows:
# Default: on # description: The cvs server sessions; service cvsserver {socket_type = streamwait = nouser = rootserver = / usr / bin / cvsserver_args = -f --allow-root = / cvsroot pserverlog_on_failure = USERIDonly_from = 192.168.0.0/24 }
The only_from is used to restrict access, and can be not or modified according to the actual situation. Modify this file permission:
# chmod 644 CVSPSERVER
Join / etc / services:
Cvsserver 2401 / TCP
Note: CVSServer is any name, but cannot be reinable with the existing service, but also to modify the first item of /etc/inetd.conf above. Here I use CVS password authentication method, CVS has other authentication methods, I have not tested, if you have experience, please add, thank you.
Add users who can use CVS to CVS groups:
Modify / etc / group as root, add the username of CVS to the CVS group, such as what I want to let the user Laser and Gumpwu can use the CVS service, then the / etc / group after the modification should have the following line:
CVS: x: 105: Laser, gumpwu
GID on your system may not be 105, there is no relationship. Mainly to separate the Laser and Gumpwu to the last colon with a comma. Of course, like the distribution of the RedHat has tools like LinuxConf, do this will be simpler. Heavy inetd makes the modification take effect:
#killall -hup inetd
If you are using XINETD system:
# /etc/rc.d/init.d/xined restart
This way the server is set up. We will then engage in the client. Setting the client if it is Linux (or other * NIX), the client and server software are the same, if it is Win, Mac and other platforms, please go to http://www.loria.fr/cgi-bin/molli/wilma .CGI / REL finds the corresponding client software, here I will talk about how to do it in Linux (* NIX):
Set environment variables cvsroot:
$ export cvsroot =: pserver: laser @ THE_SERVER_NAME: / HOME / CVSROOT
Note: The PServer here is an access method. I set it up to password authentication, so this is a PServer. If your CVS server sets a different access mode, then you need to modify it accordingly. Laser is a username that can use the CVS server. Here you can modify it according to your settings. I set up the password files of the system user in this version, that is, the Laser must be a legitimate user on the CVS server, which is of course secure. Question, CVS can be set to have its own users, I will add this content in the later version, or you can also provide some additions, or directly read CVS documents. The_server_name is the name or IP address of the CVS server. Fill in your situation, / home / cvsroot is your CVSRoot directory of your CVS server, modify or ask the administrator according to your CVS server settings. You can put this line in your shell's profile (.bash_profile, .profile, etc.) This will not have to knock a long string command each time.
Log in to the CVS server:
$ CVS login, this time CVS will ask you a password. Please knock in your password you on the CVS server. Here is the password of the system user on the CVS server:
Passwd: xxxxxxxx
After successfully logging in, you will build a .cvspass file in your home directory, you don't have to enter your password.
Ok, the client setting is complete, simple. Managing CVS server servers can be used. Now everyone is how to manage servers. For example, I want some people to read and / or write the permissions of the CVS warehouse, but don't want to give it system permissions? It is not difficult, there is a cvsroot directory in the cvs administrator user (in the cvsroot user), this directory has three profiles, passwd, readers, Writers, we can configure CVS by setting these three files. The server, the following introduces the role of these files: Passwd: CVS user list file, its format is very like shadow file: {CVS user name}: [Encrypted password]: [Equivalent system user name] If you I hope that a user is just a CVS user, not a system user, then you have to set this file. After you have just installed this file, this file may not exist, you need to create a CVS administrator user, of course, according to the format, the second field It is the user's encryption password, which is encrypted with CRYPT (3). You can write a program to do encryption, you can also use the lazy way I introduced: first create a system user, name, and CVS users, password is Prepare the CVS user password, copy the second field from / etc / shadow after creating, then remove this user. This method is more convenient to deal with fewer users, and people are not suitable, and there are also safety hazards of conflict conditions, and Root privileges, it is not good. However, the equivalent is. Write a small program is not difficult, you can search for the LinuxForum programming version, have a friend has written a post above. The third field is an equivalent system username. In fact, it is to assign an equivalent system user with a CVS user. Look at the following example you understand its function. Readers: A user list file with CVS read rights. It is a one-dimensional list. Users in this file have only read permissions for CVS. Writers: a list of users with CVS write permissions. Like readers, it is a one-dimensional list. Users in this file have write access to CVS. The above three files may not exist when the default installation, you need to create it yourself, ok, now let us use an example to teach. Suppose we have the following users to use CVS: Laser, Gumpwu, Henry, Betty, Anonymous. Where Laser and Gumpwu are system users, and Henry, Betty, Anonymous we don't want to give system user privileges, and Betty and Anonymous are read-only users, and Anonymous is even more than. So well, let's do some ready to work, first create a CVSPUB user, this user's responsibility is to read and write CVS warehouses on behalf of all non-system users. #adduser ... then edit / etc / group, let CVSPUB users in the CVS group while adding other users with system user privileges to the CVS group. (See above)
Then edit cvs administrator home directory CVSROOT / passwd file, you add the following lines: laser: $ xxefajfka; faffa33: cvspub gumpwu: $ ajfaal; 323r0ofeeanv: cvspub henry: $ fajkdpaieje: cvspub betty: fjkal; ffjieinfn /: cvspub anonymous: : CVSPUB Note: The second field above (separator is :) is a secret text password, you want to use the program or generate with my dirt. Edit the readers file, add the following line: Anonymous Betty Edit Writer file, add the following line: Laser Gumpwu Henry is OK, you will use several users to log in to test, I will find everything OK. The principles and instructions in this are not much to say, in fact, very simple, and the concept of system management users. Now the server and client are set, so how to use it, I wrote a simplest (estimate is also the most common) command: First, establish a new CVS project, usually there are some project files In this way we can use the following steps to generate a new CVS project: enter your existing project directory, such as Cvstest:
$ cd cvstest
Run command:
$ CVS IMPORT -M "this is a cvstest project" cvstest v_0_0_1 start
Note: Import is one of the commands of CVS, indicating an input project file to the CVS warehouse.
The string behind the -m parameter is a description of the text, just write some meaningful things, if not add -M
Number, then CVS will automatically run an editor (generally VI, but can modify environment variables
Editor is changed to your favorite editor. ) Let you enter information,
Cvstest is the project name (actually a warehouse name, which is stored in this name on the CVS server.
Named warehouse. )
v_0_0_1 is the total tag of this branch. No use (or not used.)
Start is a markup of the input hierarchy of the IMPORT logo file, no use.
In this way, we have built a CVS warehouse, then we can delete this test item file. Test how to get documents from the warehouse. Here I assume that all clients above have been done. Run the following command:
$ cvs checkout cvstest
Source files from the CVSTEST project are retrieved from the warehouse. If you have already done Checkout, then don't need to re-checkout, just enter the directory of the CVSTest project, update it, you will do it:
$ cd cvstest
$ CVS Update
I can. Or you don't want to update directly, just want to see if there is any update, then:
$ cvs status
After this, you will print a long string state report (you may need to display a command paging like LESS, or slowly see it in an output file.), There is a status report on each file in the project, similar This way: ================================================ =================== File: foo.c status: Up-to-Date Working Revision: 1.1.1.1 'Some Date' Repository Revision: 1.2 / HOME / CVSROOT / Cvstest / Foo.c, V Sticky Tag: (None) Sticky Date: (NONE) Sticky Options: (NONE) Here the most important thing is the Status column, there may be four states here: up-to-date: indicate you want The file is the latest. Locally Modified: Indicates that you have modified the file, but have not submitted, your version is new than the warehouse. Needing Patch: Indicates that some buddies have modified the file and have been submitted! Your version is more than the old in the warehouse. Needs Merge: Indicates that you have modified the file, but there is a non-known phase and modify this file, and it is also submitted to the warehouse! If you just want to keep the software synchronization (like me), then the above thing is enough. However, if you work together to develop a project, it is not so simple. When you participate in the project, when maintaining the file, you need more commands. For example, you are a developer of a NASDAQ project: 1. You have modified a file, such as change CEO.c, plus a line Program: Printf ("WHERE CAN I Find VC To CHEAT!"); After you finish, you have to submit a modification to the warehouse, with a command: $ cvs commit -m "add a company" CEO.c or is: $ CVS Commit - m "Worry About Money" Let CVS help you check which file needs to be submitted. 2, when I start working, maybe I first: $ cvs status, then I will see: ======================= ==================
=================================== /cvsroot/nastaq/ceo.c ,v sticky tag: (None) Sticky Date: (None) Sticky Options: (none) I know that someone has changed CEO.c, so I just: $ cvs update CEO.c or simply : $ CVS Update Update this file with this file to the latest version, and then work. Then submit it. If you have modified coo.c this day, Puts ("How About ANOTHER KIND OF Bragging?"); And submitted, but at this time I have already $ crs status, that is, I don't know your changes. And I added a line of Printf ("You Must Shameless and Seems Knowingness to Act As a Coo"); and Submitted: $ CVS Commit Co.C, CVS will tell me CVS Commit: Examing. CVS Server: Up- To-date check failed for 'coo.c' CVS [Server Aborted]: Correct Above Error First! So I know that there is a shit to make a submission, so I am here, I will report: RCS file: /home/cvsroot/nasdaq/coo.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 Merging differences between 1.1.1.1 and 1.2 into coo.c rcsmerge: warning: conflicts during merge cvs update: conflicts found in coo. C C coO.c tells you that coo.c has a version conflict, so I edited coo.c, at this time, it looks like this: ... Printf ("You Must Shameless and Seems Knowingness to Act As A Coo") ; <<<<<<< foo.c ======== ... Puts ("How About ANOTHER KIND OF Bragging?"); >>>>>>> 1.2 ... I changed the above Cheng: Printf ("You Must Shameless and Seems Knowingness to Act As a Coo"); PUTS ("How About Another Kind of Bragging?"); Then $ cvs commit -m "merge" coo.c then you update There is a new patch to play. .
. This is so recovered until all modifications are completed. However, there are some ways to pay attention to the delete program. If you delete the program PUTS ("to be honest") that you may not use; and I don't want to delete (because I use it), and I don't know directly: $ CVS Update, then my line program is finished, so we should pay attention to all developers' coordination, don't delete things, big deal with #IF 0 #ndif macro confedes. I really want to delete something, it is best to mark a version: $ cvs tag v_0_0_1 You can post and delete this version of this version in your own working directory (Note: Not deleting the warehouse.): $ Cvs Release -d Nasdaq Then you regenerate into a new branch: $ cvs RTAG -B -R v_0_0_1 v_0_0_1_1 NasDAQ then build a branch of v_0_0_1_1 $ cvs checkout -r v_0_0_1_1 NASDAQ edit and modify this branch file, this is better. However, it is important to note that the establishment of new tags and new branches is the best responsible by the management of the project. Otherwise everyone is a branch, then the warehouse is too mess. Therefore, the direct communication between the comparison developers cannot be ignored. In general, the standard mode on the Internet is an administrator (may not write a program), there is a list of posts, and everyone exchanges views on the post list and makes various resolutions. When the resolution is formed, the administrator makes a new version of the tag. Take this cycle. There are also some commands, such as adding a file GARBAGE_CHINA_CONCEPT_STOCKS_LIST: $ cvs add garbage_china_concept_stocks_list then: $ cvs commit garbage_china_concert_stocks_list looks a bit like a database in the database? It is indeed this. CVS maintains a local reference file (in CVS / ENTRIES) so that all changes can be placed on the server at once, which is safer. Similarly, if you want to delete the file bankrupted_web_site: $ rm bankrupted_web_site $ cvs remove bankrupted_web_site $ cvs commit bankrupted_web_site 3, some tips: $ Header $ mark: This mark will be put anywhere on the document to be replaced last modified cvs cvs username The file current version number, final modification time, the CVS warehouse path of the file, looks like the following: // $ header: /Home/cvsroot/simhost/simhost.cpp ,v 1.2 2001/04/20 08: 26:10 JQLiu Exp $ General We put it on the beginning, so that the programmer modifies the file very convenient, many times you just know if you start, you know if the file is the latest. $ ID $ tag: Place this tag anywhere in the file will be replaced by CVS to the last modified CVS username, the file current version number, final modification time, the CVS warehouse path of the file, looks like this: