The FreeBSD Diary |
(TM) | Providing practical examples since 1998If you buy from Amazon USA, please support us by using this link. |
cvs - create your own repository
25 April 2000
|
cvs is an open source version control software. It is
pretty widely used. It also forms the basis for the FreeBSD source code tree.
This article talks about creating a cvs repository for your own project. You can
put anything into cvs so long as it's in a file. I'm using cvs for storing
the source code for FreshPorts. Don't confuse cvsup with cvs. cvs is a separate program. cvsup is used to get data from a cvsup server, which in turn, reads from a cvs repository. Also, I am by no means a cvs expert. I'm just writing down what I did so when I go to do it again, I have my notes. Of course, corrections and additions are always welcome in the comments section. |
Resources
|
Here are some useful cvs resources:
And more recently (29 September 2000) found:
And more recently (11 January 2001) found:
|
Creating the cvs repository
|
The first step is to create the cvs repository (also known as a
tree).
If you now look in ~/mycvs, you'll find the basic files which constitute a repository. |
Adding your project to the repository
|
Now we'll add your project to the repository.
This instructs cvs to import the files located in the current directory. cvs uses the value of CVSROOT to determine which tree the files will be imported into. You should note the following points about the above command:
See man cvs for more detail. |
Importing a vendor branch
|
I import vendor branches for the third party software which I use within my websites. For example, Phorum and phpPgAds. When a new release comes out, I import that source code into my CVS Repository. This makes it easier for me to maintain my local customizations of these popular software packages. Here I am importing the latest version of Phorum:
To resolve the conflicts, I did this:
CVS was unable to resolve conflicts in
|
Checking out the files
|
The first step in modifying something from your repository is to check out
the files. So I did this:
mkdir /home/dan/work/myproject cvs co myproject Note that "myproject" is the name of the module we created when we did the import. However, the above will place the files in /home/dan/work/myproject. If you want the files to be placed into the current directory and you don't want cvs to create a subdirectory, try this instead: mkdir /home/dan/work/myproject cvs co -d . myproject |
Checking out a single file
|
If youi want to get a single file from the repository, you do it like
this:
cvs co myproject/the.file.i.want If you want a particular revision of that file: cvs co -r1.1 myproject/the.file.i.want That will give you revision 1.1 of that file. Perhaps the file lives in a subdirectory of the project. No problem. Just supply the pathname cvs co myproject/path/to/the.file.i.want |
What's changed?
|
Now you can make your changes. To see what's changed between your
work files and your repository, use this command:
cvs diff Or compare the current files against revision 1.3: cvs diff -r1.3 category-watch.php3 |
Adding new files to the repository
|
If a new file is needed, you can add it to the repository by doing this:
$ cvs add mynewscript.pl cvs add: scheduling file 'mynewscript.pl' for addition On your next commit, the file will be added to the repository. |
Checking things back in
|
Once you are happy with any changes you have made, you can commit these
changes to the repository by doing this:
cvs commit |
cvs commit: Up-to-date check failed for `about.html'
|
Sometimes, when you try to commit stuff back to the database, things don't
go as planned. For example:
$ cvs commit cvs commit: Examining . cvs commit: Up-to-date check failed for `about.html' cvs commit: Examining _private cvs commit: Examining graphics cvs commit: Examining images cvs commit: Examining scripts cvs commit: Examining work cvs commit: Examining work/graphics cvs [commit aborted]: correct above errors first! It was suggested to me that about.html was older than that which was in the repository and that I should try this instead: $ cvs update about.html RCS file: /home/dan/mycvs/freshports/about.html,v retrieving revision 1.1.1.1 retrieving revision 1.2 Merging differences between 1.1.1.1 and 1.2 into about.html about.html already contains the differences between 1.1.1.1 and 1.2 That worked for me! |
other useful options
|
This section shows you some interesting options.
# cvs status category-watch.php3 =================================================================== File: category-watch.php3 Status: Locally Modified Working revision: 1.3 Mon May 1 13:35:50 2000 Repository revision: 1.3 /home/dan/mycvs/freshports/category -watch.php3,v Sticky Tag: (none) Sticky Date: (none) Sticky Options: (none)
cvs history -c category-watch.php3 |
Backing out a commit
30 September 2003
|
You made a mistake. You committed something you didn't want to commit. There
is an easy way to undo those changes and commit a new revision.
For our example, we'll assume the last commit
created revision 1.4. We want to reverse all of those changes. We want revision
to go back to what we had in revision 1.3. By the nature of a repository, all revisions are held forever.
We will use the features of cvs to automatically undo the changes for ut.
The file we need to change is freshports.php .
A very useful cvs feature is the ability to merge changes between revision. The following command merges the changes between the two revisions into the working copy of the file:
The order of the revisions is important. In this case, we first specify the revision containing the mistaken commit first, and then the revision we wish to which we want to revert. After executing the above command, check that your working copy is identical to revision 1.3:
After verifying this is how we want the file to look, we commit:
Done. Revision committed. We're back with what we had in revision 1.3. |