版本管理:RCS之命令基础篇

来源:互联网 发布:暴雪嘉年华 知乎 编辑:程序博客网 时间:2024/05/24 05:41

RCS作为非常古老的版本工具,远远在SVN和已经退役的CVS之前。它的古老程度应该比Web开发的ASP前代的CGI还要久远。但是作为非常简单的文本格式的版本管理工具,它使用时间跨度之久令人惊奇。如果想对版本管理实现方式进行深入研究的话,RCS提供了一种最为简单的方式,,v文件是RCS的全部,以文本形式存放,简单易读,对于想深入了解版本管理或者想开发类似工具的开发者来说,绝对是可以借鉴的。

安装

比如像centos等,新的centos7之前应该都是被缺省安装的。如果没有的话,yum install rcs即可。230k左右的package,可以完成很多的功能。

=================================================================================================================================================== Package                         Arch                               Version                                 Repository                        Size===================================================================================================================================================Installing: rcs                             x86_64                             5.9.0-5.el7                             base                             230 kTransaction Summary===================================================================================================================================================

版本确认

[root@host31 ~]# rcs --versionrcs (GNU RCS) 5.9.0Copyright (C) 2010-2013 Thien-Thi NguyenCopyright (C) 1990-1995 Paul EggertCopyright (C) 1982,1988,1989 Walter F. Tichy, Purdue CSLicense GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law.[root@host31 ~]#

checkin命令:ci

准备

[root@host31 ~]# mkdir -p /local/testrcs[root@host31 ~]# cd /local/testrcs[root@host31 testrcs]# mkdir RCS[root@host31 testrcs]# echo "#include <stdio.h>" >hello.h

checkin命令:ci

[root@host31 testrcs]# ci hello.hRCS/hello.h,v  <--  hello.henter description, terminated with single '.' or end of file:NOTE: This is NOT the log message!>> initial version>> .initial revision: 1.1done[root@host31 testrcs]#

checkin后的确认,发现文件不见了,只有RCS下生成的,v文件了

[root@host31 testrcs]# lltotal 0drwxr-xr-x. 2 root root 22 Aug 15 21:48 RCS[root@host31 testrcs]# ll RCStotal 4-r--r--r--. 1 root root 213 Aug 15 21:48 hello.h,v[root@host31 testrcs]# cat RCS/hello.h,vhead    1.1;access;symbols;locks; strict;comment @ * @;1.1date    2016.08.15.17.47.54;    author root;    state Exp;branches;next    ;desc@initial version@1.1log@Initial revision@text@#include <stdio.h>@[root@host31 testrcs]#

再看hello.h,v文件你会清晰地发现版本管理中需要考虑的东西内容,branch/lock/log/tag/操作等,你在SVN中能做到的事情RCS同样可以做到,只不过有时需要再封装一层。在没有SVN和git甚至没有CVS的时代我们就曾经通过自己封装RCS做到多项目同时开发,branch/tag/自动merge无所不能,工具本身没有所谓那个更好,对我们来说只是方便和合适最为重要。

checkout命令:co

[root@host31 testrcs]# lltotal 0drwxr-xr-x. 2 root root 22 Aug 15 21:48 RCS[root@host31 testrcs]# co hello.hRCS/hello.h,v  -->  hello.hrevision 1.1done[root@host31 testrcs]#

修正差分确认:rcsdiff

准备:事前lock住要修正的文件。

[root@host31 testrcs]# co -l hello.hRCS/hello.h,v  -->  hello.hrevision 1.1 (locked)done[root@host31 testrcs]#

在hello.h中增加一行

[root@host31 testrcs]# cat hello.h#include <stdio.h>#include <string.h>[root@host31 testrcs]#

checkin之前确认差分

[root@host31 testrcs]# rcsdiff hello.h===================================================================RCS file: RCS/hello.h,vretrieving revision 1.1diff -r1.1 hello.h1a2> #include <string.h>[root@host31 testrcs]#

checkin, 在1.1的版本之上生成1.2,ci -u即可保证本地文件在checkin之后不被删除。

[root@host31 testrcs]# ci -u hello.hRCS/hello.h,v  <--  hello.hnew revision: 1.2; previous revision: 1.1enter log message, terminated with single '.' or end of file:>> add string.h>> .done[root@host31 testrcs]# lltotal 4-r--r--r--. 1 root root 39 Aug 15 22:00 hello.hdrwxr-xr-x. 2 root root 22 Aug 15 22:03 RCS[root@host31 testrcs]#

也可以使用如下的方式进行确认

[root@host31 testrcs]# rcsdiff -r1.1 -r1.2 hello.h===================================================================RCS file: RCS/hello.h,vretrieving revision 1.1retrieving revision 1.2diff -r1.1 -r1.21a2> #include <string.h>[root@host31 testrcs]#

创建branch

[root@host31 testrcs]# ci -r2.0 -f -m "initial" hello.hRCS/initial,v  <--  initialci: initial: No such file or directoryRCS/hello.h,v  <--  hello.hnew revision: 2.0; previous revision: 1.2done[root@host31 testrcs]#[root@host31 testrcs]# co -l hello.hRCS/hello.h,v  -->  hello.hrevision 2.0 (locked)done[root@host31 testrcs]#[root@host31 testrcs]# rcsdiff hello.h===================================================================RCS file: RCS/hello.h,vretrieving revision 2.0diff -r2.0 hello.h2a3> #include "test.h"[root@host31 testrcs]#[root@host31 testrcs]# ci -u hello.hRCS/hello.h,v  <--  hello.hnew revision: 2.1; previous revision: 2.0enter log message, terminated with single '.' or end of file:>> modify for 2.0>> .done[root@host31 testrcs]#

在2.1的版本上继续lock,修改,checkin,发现只能继续生成2.2的版本

[root@host31 testrcs]# co -l -r2.1 hello.hRCS/hello.h,v  -->  hello.hrevision 2.1 (locked)done[root@host31 testrcs]# vi hello.h[root@host31 testrcs]# rcsdiff hello.h===================================================================RCS file: RCS/hello.h,vretrieving revision 2.1diff -r2.1 hello.h3a4> #include "test2.1.h"[root@host31 testrcs]# ci -u -m "add test2.1.h" hello.hRCS/add test2.1.h,v  <--  add test2.1.hci: add test2.1.h: No such file or directoryRCS/hello.h,v  <--  hello.hnew revision: 2.2; previous revision: 2.1done[root@host31 testrcs]#

如果我们现在对旧的版本1.1进行lock,然后修正,然后checkin会发生什么呢

[root@host31 testrcs]# co -l -r1.1 hello.hRCS/hello.h,v  -->  hello.hrevision 1.1 (locked)done[root@host31 testrcs]# vi hello.h[root@host31 testrcs]# rcsdiff hello.h===================================================================RCS file: RCS/hello.h,vretrieving revision 2.2diff -r2.2 hello.h2,4c2< #include <string.h>< #include "test.h"< #include "test2.1.h"---> #include "test1.1.h"[root@host31 testrcs]# ci -u -m "add test1.1.h" hello.hRCS/add test1.1.h,v  <--  add test1.1.hci: add test1.1.h: No such file or directoryRCS/hello.h,v  <--  hello.hnew revision: 1.1.1.1; previous revision: 1.1done[root@host31 testrcs]#

1.0/2.0进行大的Trunk管理,在其下生成的1.1 2.1等进行lock,进一步生成第一层的Branch,这是个4位的版本号,1.1.1.1, 第四位是文件自身的版本号,第三位第一层Branch号,第一位和第二位结合起来为发生branch的位置。能不能生成2层的branch呢,答案是肯定的,如果项目有奇葩的需求的话,你可以继续往下生成branch。现在你的版本号是1.1.1.1.1.1了,够不够长。

[root@host31 testrcs]# co -l -r1.1.1.1 hello.hRCS/hello.h,v  -->  hello.hrevision 1.1.1.1 (locked)done[root@host31 testrcs]# vi hello.h[root@host31 testrcs]# rcsdiff hello.h===================================================================RCS file: RCS/hello.h,vretrieving revision 2.2diff -r2.2 hello.h2,4c2,3< #include <string.h>< #include "test.h"< #include "test2.1.h"---> #include "test1.1.h"> #include "test1.1.1.1.h"[root@host31 testrcs]#[root@host31 testrcs]# ci -u -m "add test1.1.1.1.h" hello.hRCS/add test1.1.1.1.h,v  <--  add test1.1.1.1.hci: add test1.1.1.1.h: No such file or directoryRCS/hello.h,v  <--  hello.hnew revision: 1.1.1.2; previous revision: 1.1.1.1done[root@host31 testrcs]#[root@host31 testrcs]# co -l -r1.1.1.1 hello.hRCS/hello.h,v  -->  hello.hrevision 1.1.1.1 (locked)done[root@host31 testrcs]# vi hello.h[root@host31 testrcs]# rcsdiff hello.h===================================================================RCS file: RCS/hello.h,vretrieving revision 2.2diff -r2.2 hello.h2,4c2,3< #include <string.h>< #include "test.h"< #include "test2.1.h"---> #include "test1.1.h"> #include "test1.1.1.1.branch.h"[root@host31 testrcs]# ci -u -m "1.1.1.1 branch" hello.hRCS/1.1.1.1 branch,v  <--  1.1.1.1 branchci: 1.1.1.1 branch: No such file or directoryRCS/hello.h,v  <--  hello.hnew revision: 1.1.1.1.1.1; previous revision: 1.1.1.1done[root@host31 testrcs]#

rlog确认详细信息

[root@host31 testrcs]# rlog hello.hRCS file: RCS/hello.h,vWorking file: hello.hhead: 2.2branch:locks: strictaccess list:symbolic names:keyword substitution: kvtotal revisions: 8;     selected revisions: 8description:initial version----------------------------revision 2.2date: 2016/08/15 22:13:25;  author: root;  state: Exp;  lines: +1 -0*** empty log message ***----------------------------revision 2.1date: 2016/08/15 22:10:19;  author: root;  state: Exp;  lines: +1 -0modify for 2.0----------------------------revision 2.0date: 2016/08/15 22:07:41;  author: root;  state: Exp;  lines: +0 -0*** empty log message ***----------------------------revision 1.2date: 2016/08/15 22:03:45;  author: root;  state: Exp;  lines: +1 -0add string.h----------------------------revision 1.1date: 2016/08/15 21:47:54;  author: root;  state: Exp;branches:  1.1.1;Initial revision----------------------------revision 1.1.1.2date: 2016/08/15 22:31:13;  author: root;  state: Exp;  lines: +1 -0*** empty log message ***----------------------------revision 1.1.1.1date: 2016/08/15 22:15:10;  author: root;  state: Exp;  lines: +1 -0branches:  1.1.1.1.1;*** empty log message ***----------------------------revision 1.1.1.1.1.1date: 2016/08/15 22:32:27;  author: root;  state: Exp;  lines: +1 -0*** empty log message ***=============================================================================[root@host31 testrcs]#

rlog -h 则可以单独列出symbolicnames等信息

[root@host31 testrcs]# rlog -h hello.hRCS file: RCS/hello.h,vWorking file: hello.hhead: 2.2branch:locks: strictaccess list:symbolic names:keyword substitution: kvtotal revisions: 8=============================================================================[root@host31 testrcs]#

修改注释 rcs -m

修正前rlog信息

revision 1.1date: 2016/08/15 21:47:54;  author: root;  state: Exp;branches:  1.1.1;Initial revision
[root@host31 testrcs]# rcs -m1.1:"initial version" hello.hRCS file: RCS/hello.h,vdone[root@host31 testrcs]#

修正后rlog信息

revision 1.1date: 2016/08/15 21:47:54;  author: root;  state: Exp;branches:  1.1.1;initial version

注意:-m和版本之间不能有空格等细小的事项

管理symbolic names: rcs -n

为什么要用symbolic names,很简单,作tag。使用方便的管理工具的时候你可能不会意识到版本管理工具替你做了什么,但是用RCS,需要一个文件一个文件的设定上tag,无论什么样的版本管理工具,他们都应该是类似,有一种特定的方法将某一时间断面的所有文件进行整体管理。现代的版本管理工具不会让你如此麻烦,但同时也拿去了我们了解其实际运作的机会。

[root@host31 testrcs]# rcs -nNewBranch:1.1.1.1.1.1 hello.hRCS file: RCS/hello.h,vdone[root@host31 testrcs]# rlog -h hello.hRCS file: RCS/hello.h,vWorking file: hello.hhead: 2.2branch:locks: strictaccess list:symbolic names:        NewBranch: 1.1.1.1.1.1keyword substitution: kvtotal revisions: 8=============================================================================[root@host31 testrcs]#

删除symbolic names

[root@host31 testrcs]# rcs -nNewBranch hello.hRCS file: RCS/hello.h,vdone[root@host31 testrcs]# rcs -h hello.hrcs: unknown option: -h[root@host31 testrcs]# rlog -h hello.hRCS file: RCS/hello.h,vWorking file: hello.hhead: 2.2branch:locks: strictaccess list:symbolic names:keyword substitution: kvtotal revisions: 8=============================================================================[root@host31 testrcs]#

注意事项:-nname:rev 的版本如果不存在的时候会出错,注意空格

删除版本 rcs -o

删除1.1.1.1.1.1这个很闹心的版本

[root@host31 testrcs]# rcs -o1.1.1.1.1.1 hello.hRCS file: RCS/hello.h,vdeleting revision 1.1.1.1.1.1done[root@host31 testrcs]#

除了指定版本删除,还有可以指定from和to的一定范围的删除方式

方式 详细说明 rev1:rev2 从rev1删到rev2 rev1: 删除rev1开始的分支所有版本 :rev2 删除到rev2的所有版本

此操作无比凶险,执行之前务必保存好,v文件以便恢复

1 0
原创粉丝点击