CVS 的使用

参考 EmacsCvs

如何创建一个 repository

$cvs -d ~/tmp/testcvsroot/ init
-d 用于指明一个 repository,常用的描述方式可以是:

1. "~/tmp/testcvsroot/" 一个目录。 1. ":pserver:username@servername:/path/to/cvsroot" 一个网络地址。 1. 还有其它的 ext, rsh, ssh 等等方式。

使用 ssh 方式 访问 cvs .

- 在 Windows 环境下,使用 cygwin 来 checkout 一个项目 .

$export CVS_RSH=SSH
$cvs -d:ext:username@servername:/home/username/cvsroot co projectname
这样做有一个缺点就是每一次都操作都需要输入密码.

- 使用 WinCVS 和 putty

待续 ...

如何在 cvs 系统中建立一个新的工程

$export CVSROOT=/path/to/cvsroot
$cd /path/to/project/rootpath
$ls
src doc include lib
$pwd
/path/to/project/rootpath
$cvs import -m "log message" projectname vendertag releasetag
vendertag 可以使用创建工程的人的名字,releasetag 可以用 "start"

创建完之后目录 /path/to/project/rootpath 就没有用了。

$tar -zcf backup.tar.gz /path/to/project/rootpath
$rm -fr /path/to/project/rootpath

如何创建一个本地的 working copy

$export CVSROOT=/path/to/cvsroot
$mkdir ~/workingplace
$cvs checkout projectname

如何将自己的改动存入CVS中

$export CVSROOT=/path/to/cvsroot
$cvs commit

如果在有人在你 commit 之前先 commit 一些改动,而且他和你 改了同一个文件,cvs会提示需要 need merge 这个时候,你需要先 update,改动可能冲突的语句,再commit。

如何建立自己的branch

 $export CVSROOT=/path/to/cvsroot cvs tag -b branchname

这时,cvs就会记录下当前的版本,生成一个branch,其 规则为当前版本号.branch号码.该branch版本如:当前版 本为1.14,执行cvs tag -b branchname,就会得到一个版 本号为:1.14.2的branch,用cvs status查看状态的到文 件版本号为:1.14.2.1。需要注意的是:当你建立一个 branch以后,当前的工作branch并没有改变,如果你需要 在新建的branch上工作,就需要输入cvs update -r branchname

CVS Update 命令的用法

如果你在

cvs update 1.cc
之前改动了 1.cc , 会改变 1.cc 的内容,但是不会轻易丢掉你所 做的改动。

working copy 中的每一个文件在 repository中都有一个对应 revision , update 命令只会修改对应的 revision 。

如果你在 commit 的时候, cvs 发现 repository 中的 revision 比你的 working copy 中对应的 revision 还要大,那么 说明有人在你之前 commit 过了这个文件,也就是说,有人和你同时 修改了同一个文件,而且他先于你 commit 了,所以你一定要 cvs update ,让 working copy 和最新的 revision 合并。 如果你和别人的修改不在同一个地方,那么 cvs 自动合并,如果 你和别人的修改在同一个地方,那么就把你的修改和别人的修改都写 在文件中,等待你用手工解决冲突。

如何合并一个 branch

假如当前的 CVS 的情形如下

     +-----+    +-----+    +-----+    +-----+
     ! 1.1 !----! 1.2 !----! 1.3 !----! 1.4 !      <- The main trunk
     +-----+    +-----+    +-----+    +-----+
                     !
                     !
                     !   +---------+    +---------+
     Branch R1fix -> +---! 1.2.2.1 !----! 1.2.2.2 !
                         +---------+    +---------+
$ cvs update -j R1fix m.c        # Merge all changes made on the branch,
                                 # i.e. the changes between revision 1.2
                                 # and 1.2.2.2, into your working copy
                                 # of the file.
那么就变成了下面的情形
   +-----+    +-----+    +-----+    +-----+    +-----+
     ! 1.1 !----! 1.2 !----! 1.3 !----! 1.4 !----! 1.5 !   <- The main trunk
     +-----+    +-----+    +-----+    +-----+    +-----+
                     !                           *
                     !                          *
                     !   +---------+    +---------+    +---------+
     Branch R1fix -> +---! 1.2.2.1 !----! 1.2.2.2 !----! 1.2.2.3 !
                         +---------+    +---------+    +---------+

其他命令

cvs update -j 1.2.2.2 -j R1fix m.c    # Merge changes from 1.2.2.2 to the
                                           # head of the
                                           R1fix branch
cvs update -j R1fix:yesterday -j R1fix m.c
cvs update -j merged_from_R1fix_to_trunk -j R1fix m.c

cvs update 的命令如果只有一个 -j ,那么表示但前的 working version 和 -j 指定的 version 之间共同的祖先和 -j 指定的version 之间的区别,应用到 working version 上 去。

cvs watch 的用法。

这个命令的作用是: 你 checkout 出来的文件是只读的,只有 cvs edit 命令之后,才可以 编辑。类似 MS Source Safe 的操作方式。