CVS 入门

入门第一步:设环境、初始化

首先,在~/.cshrc 中加入

setenv CVSROOT $HOME/cvsroot

然后进行初始化:

source ~/.cshrc
cvs init

运行完之后,在 $HOME 下就会出现一个 cvsroot 目录,其中有一个 CVSROOT 目录,该目录中有一大堆文件,要想知道每个文件具体是干什么的就只有慢慢学了!

程序导入(import)

假定我们要维护的程序在目录 myproj 下,在导入前,首先将 mypoj 下所有的垃圾文件(包括目标文件、备份文件以及可执行文件,等等)删除掉。然后运行下列命令:

cvs import -m "initial version" myproj  jrandom  start

该命令将程序导入到($CVSROOT)中,如果要导到另一仓库,可以指定路径

cvs -d [仓库路径]  import

导出工作拷贝(checkout)

当 myproj 被导入 CVS 中以后,就不应再在原文件上进行修改了,因为原来的文件并不在版本控制序列之中。正确的做法是在一个“工作拷贝”(working copy)上进行修改,故应运行如下命令:

mv myproj myproj-old    (或 rm -r -f myproj)
cvs checkout myproj

这样就得到了一个工作拷贝,它与原目录的结构和内容几乎完全相同,只是在每一个子目录下多了一个CVS目录。

版本同步(update)

该命令的形式为:

cvs update

其作用是使工作拷贝的版本与仓库中的最新版本同步,将别人的修改以补丁(patch)的形式合并进自己的拷贝中,其作用主要体现于协同开发。此外,更新时可能出现冲突,此时就需要两个人进行协商解决。

仓库版本升级(commit)

命令格式为:

cvs commit -m "change message" [filename]

其中“-m”选项是必须的,如果没有加的话,系统会自动打开一个编辑器让你输入修改信息。

显示信息常用命令

常用的有:

cvs diff -c     (比较当前工作拷贝与最高版本的区别)
cvs status      (显示当前工作拷贝的状态)
cvs log         (查看修改历史)

回到前面的版本(从 1.4 回到 1.2)

1. 慢速方法

(1). 查看当前最高版本文件的内容
     cvs -Q update -p [filename]
(2). 查看1.2是否是所需版本
     cvs -Q update -p -r 1.2 [filename]
(3). 若已确认, 则
     cvs -Q update -p -r 1.2 [filename] > [filename]
(4). 更新仓库
	 cvs commit -m "reverted to 1.2 code" [filename]

这样就产生了版本1.5,但其内容与1.2完全相同。这也就是说,版本号是在不断升高的,但其内容可以回到过去。

2. 快速方法

cvs update -j 1.4 -j 1.2 [filename]

注:这里介绍的两种方法都是处理单个文件的,对于多个文件的处理稍后再补上。

添加文件

分两步

cvs add [newfiles]
cvs commit -m "add newfiles" [newfiles]

删除文件

分三步

rm [filenames]    (删除工作拷贝中的文件)
cvs remove [filenames]
cvs commit -m "remone files" [filenames]

添加目录

只需一步,无需“commit”

mkdir subdir    (该命令不算一步)
cvs add subdir

删除目录

1. 首先要删除目录中所有的文件

cd subdir
rm file1 file2 ...
cvs remove file1 file2 ...
cvs commit -m "rm all files in subdir" file1 file2 ...

2. 然后再在上一级目录运行

cvs update -P

该命令是删除当前目录下所有的空目录。实际上,空目录只是从工作拷贝中消失,而仓库中还有一个空目录。

文件重命名

其基本思想是:删除旧文件,添加新文件。具体过程为:

mv oldname newname
cvs remove oldname
cvs add newname
cvs commit -m "mv oldname newname" oldname newname

目录重命名

其基本思想是:建一个新目录,将旧目录中的文件移到新目录中,再分别在新旧目录中进行添加和删除操作,最后是删除空目录。具体过程为:

mkdir newdir
cvs add newdir
mv olddir/* newdir
cd olddir
cvs rm file1  file2 ...
cd ../newdir
cvs add file1 file2 ...
cd ..
cvs commit -m "rename dir"
cvs update -P

CVS 配置文件

有时我们经常用到一些选项,每次都输入比较麻烦,解决的办法是在家目录下建立一个配置文件:.cvsrc,其内容如下:

diff -c
update -P

建立了此文件之后

cvs diff   就相当于  cvs diff -c

此处,“ diff ”若简写为“ di ”则配置文件中的绑定无效。

命令简写

CVS的命令都比较长,所以它提供了简写方式。只要在 shell 命令行中输入:

cvs --help-synonyms

就可以得到如下命令简写列表:

CVS command synonyms are:
        add          ad new
        admin        adm rcs
        annotate     ann
        checkout     co get
        commit       ci com
        diff         di dif
        export       exp ex
        history      hi his
        import       im imp
        log          lo
        login        logon lgn
        rannotate    rann ra
        rdiff        patch pa
        release      re rel
        remove       rm delete
        rlog         rl
        rtag         rt rfreeze
        status       st stat
        tag          ta freeze
        update       up upd
        version      ve ver

几个常用 Shell 命令

由上面的介绍可知,在 CVS 中增减文件或目录是一件麻烦事,为了简化该过程,我(姓王名亮)特意写了如下几个常用 Shell 命令以惠世人,敬请积极试用,发现问题请及时告知。但事先声明的是:由于用本命令所造成的损失,鄙人概不负责!:-)

1. /usr/local/bin/cvs-add

命令格式: cvs-add [file list] [directory list]
    功能: 在 CVS 添加目录和文件

其源代码如下:

#!/bin/tcsh -f

#add files or diretories in CVS

set ffdd=`echo $*`

foreach fd ($ffdd)
  if(-d $fd) then
# rm the diretories in directory $fd
    set CVSdir=`find $fd -type d -name "CVS"`
    rm -r -f $CVSdir
# find the files and directories in directory $fd
    set ff=`find $fd -type f`
    set dd=`find $fd -type d`
# add directories
    cvs add $dd
# add files
    cvs add $ff
    cvs commit -m "add files in directory '$fd'"
  else
    cvs add $fd
    cvs commit -m "add file '$fd'" $fd
  endif
end

2. /usr/local/bin/cvs-rm

命令格式: cvs-rm [file list] [directory list]
    功能: 在 CVS 删除目录和文件(同时删除仓库和工作拷贝中的目录和文件)

其源代码如下:

#!/bin/tcsh -f

#remove files or diretories in CVS

set ffdd=`echo $*`

echo "你真的要删除 $* 吗?(y/n)"
set flag = $<
if($flag == 'y') then
  echo "你真的不后悔吗?(y/n)"
  set flag2 = $<
  if($flag2 == 'y') then
    foreach fd ($ffdd)
      if(-d $fd) then
        echo "rm $fd from CVS"
# find the files and directories in directory $fd  
        set ff=`find $fd -type f`
# find the files in $fd (not include the files in CVS)
        foreach f ($ff)
          echo $f >>ffftmp
        end
        set fff=`cat ffftmp | sed -e '/CVS/d'`
        rm  ffftmp  -f
# remove the file from CVS permanently     
        if ($%fff > 0) then
          rm $fff -f
          cvs remove $fff
          cvs commit -m "rm files in directory '$fd'" $fff
        endif
# rm directories
        set Root=`cat $fd/CVS/Root `
        set Repository=`cat $fd/CVS/Repository`
        rm -r -f $fd
        echo "rm $Root/$Repository"
        rm -r -f $Root/$Repository
      else
        rm -f $fd
        cvs remove $fd
        cvs commit -m "rm file '$fd'" $fd
      endif
    end
    echo "唉!你现在后悔也晚了!:-) "
  endif
endif

3. /usr/local/bin/cvs-rmCVS

命令格式: cvs-rmCVS [directory list]
    功能: 删除指定目录及其子目录中的 CVS 目录。

其源代码如下:

#!/bin/tcsh -f

set ffdd=`echo $*`

foreach fd ($ffdd)
  if(-d $fd) then
# rm the diretories CVS in directory $fd
    set CVSdir=`find $fd -type d -name "CVS"`
    rm -r -f $CVSdir
  endif
end
[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8570952/viewspace-912153/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/8570952/viewspace-912153/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值