版本管理 RCS之命令基础篇
Posted firsttry
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了版本管理 RCS之命令基础篇相关的知识,希望对你有一定的参考价值。
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 k
Transaction Summary
===================================================================================================================================================
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
版本确认
[root@host31 ~]# rcs --version
rcs (GNU RCS) 5.9.0
Copyright (C) 2010-2013 Thien-Thi Nguyen
Copyright (C) 1990-1995 Paul Eggert
Copyright (C) 1982,1988,1989 Walter F. Tichy, Purdue CS
License 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 ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
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
- 1
- 2
- 3
- 4
checkin命令:ci
[[email protected] testrcs]# ci hello.h
RCS/hello.h,v <-- hello.h
enter description, terminated with single ‘.‘ or end of file:
NOTE: This is NOT the log message!
>> initial version
>> .
initial revision: 1.1
done
[[email protected] testrcs]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
checkin后的确认,发现文件不见了,只有RCS下生成的,v文件了
[root@host31 testrcs]# ll
total 0
drwxr-xr-x. 2 root root 22 Aug 15 21:48 RCS
[root@host31 testrcs]# ll RCS
total 4
-r--r--r--. 1 root root 213 Aug 15 21:48 hello.h,v
[root@host31 testrcs]# cat RCS/hello.h,v
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2016.08.15.17.47.54; author root; state Exp;
branches;
next ;
desc
@initial version
@
1.1
log
@Initial revision
@
text
@#include <stdio.h>
@
[root@host31 testrcs]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
再看hello.h,v文件你会清晰地发现版本管理中需要考虑的东西内容,branch/lock/log/tag/操作等,你在SVN中能做到的事情RCS同样可以做到,只不过有时需要再封装一层。在没有SVN和git甚至没有CVS的时代我们就曾经通过自己封装RCS做到多项目同时开发,branch/tag/自动merge无所不能,工具本身没有所谓那个更好,对我们来说只是方便和合适最为重要。
checkout命令:co
[root@host31 testrcs]# ll
total 0
drwxr-xr-x. 2 root root 22 Aug 15 21:48 RCS
[root@host31 testrcs]# co hello.h
RCS/hello.h,v --> hello.h
revision 1.1
done
[root@host31 testrcs]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
修正差分确认:rcsdiff
准备:事前lock住要修正的文件。
[root@host31 testrcs]# co -l hello.h
RCS/hello.h,v --> hello.h
revision 1.1 (locked)
done
[root@host31 testrcs]#
- 1
- 2
- 3
- 4
- 5
在hello.h中增加一行
[root@host31 testrcs]# cat hello.h
#include <stdio.h>
#include <string.h>
[root@host31 testrcs]#
- 1
- 2
- 3
- 4
checkin之前确认差分
[[email protected] testrcs]# rcsdiff hello.h
===================================================================
RCS file: RCS/hello.h,v
retrieving revision 1.1
diff -r1.1 hello.h
1a2
> #include <string.h>
[[email protected] testrcs]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
checkin, 在1.1的版本之上生成1.2,ci -u即可保证本地文件在checkin之后不被删除。
[[email protected] testrcs]# ci -u hello.h
RCS/hello.h,v <-- hello.h
new revision: 1.2; previous revision: 1.1
enter log message, terminated with single ‘.‘ or end of file:
>> add string.h
>> .
done
[[email protected] testrcs]# ll
total 4
-r--r--r--. 1 root root 39 Aug 15 22:00 hello.h
drwxr-xr-x. 2 root root 22 Aug 15 22:03 RCS
[[email protected] testrcs]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
也可以使用如下的方式进行确认
[[email protected] testrcs]# rcsdiff -r1.1 -r1.2 hello.h
===================================================================
RCS file: RCS/hello.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -r1.1 -r1.2
1a2
> #include <string.h>
[[email protected] testrcs]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
创建branch
[root@host31 testrcs]# ci -r2.0 -f -m "initial" hello.h
RCS/initial,v <-- initial
ci: initial: No such file or directory
RCS/hello.h,v <-- hello.h
new revision: 2.0; previous revision: 1.2
done
[root@host31 testrcs]#
[root@host31 testrcs]# co -l hello.h
RCS/hello.h,v --> hello.h
revision 2.0 (locked)
done
[root@host31 testrcs]#
[root@host31 testrcs]# rcsdiff hello.h
===================================================================
RCS file: RCS/hello.h,v
retrieving revision 2.0
diff -r2.0 hello.h
2a3
> #include "test.h"
[root@host31 testrcs]#
[root@host31 testrcs]# ci -u hello.h
RCS/hello.h,v <-- hello.h
new revision: 2.1; previous revision: 2.0
enter log message, terminated with single ‘.‘ or end of file:
>> modify for 2.0
>> .
done
[root@host31 testrcs]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
在2.1的版本上继续lock,修改,checkin,发现只能继续生成2.2的版本
[[email protected] testrcs]# co -l -r2.1 hello.h
RCS/hello.h,v --> hello.h
revision 2.1 (locked)
done
[[email protected] testrcs]# vi hello.h
[[email protected] testrcs]# rcsdiff hello.h
===================================================================
RCS file: RCS/hello.h,v
retrieving revision 2.1
diff -r2.1 hello.h
3a4
> #include "test2.1.h"
[[email protected] testrcs]# ci -u -m "add test2.1.h" hello.h
RCS/add test2.1.h,v <-- add test2.1.h
ci: add test2.1.h: No such file or directory
RCS/hello.h,v <-- hello.h
new revision: 2.2; previous revision: 2.1
done
[[email protected] testrcs]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
如果我们现在对旧的版本1.1进行lock,然后修正,然后checkin会发生什么呢
[[email protected] testrcs]# co -l -r1.1 hello.h
RCS/hello.h,v --> hello.h
revision 1.1 (locked)
done
[[email protected] testrcs]# vi hello.h
[[email protected] testrcs]# rcsdiff hello.h
===================================================================
RCS file: RCS/hello.h,v
retrieving revision 2.2
diff -r2.2 hello.h
2,4c2
< #include <string.h>
< #include "test.h"
< #include "test2.1.h"
---
> #include "test1.1.h"
[[email protected] testrcs]# ci -u -m "add test1.1.h" hello.h
RCS/add test1.1.h,v <-- add test1.1.h
ci: add test1.1.h: No such file or directory
RCS/hello.h,v <-- hello.h
new revision: 1.1.1.1; previous revision: 1.1
done
[[email protected] testrcs]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
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了,够不够长。
[[email protected] testrcs]# co -l -r1.1.1.1 hello.h
RCS/hello.h,v --> hello.h
revision 1.1.1.1 (locked)
done
[[email protected] testrcs]# vi hello.h
[[email protected] testrcs]# rcsdiff hello.h
===================================================================
RCS file: RCS/hello.h,v
retrieving revision 2.2
diff -r2.2 hello.h
2,4c2,3
< #include <string.h>
< #include "test.h"
< #include "test2.1.h"
---
> #include "test1.1.h"
> #include "test1.1.1.1.h"
[[email protected] testrcs]#
[[email protected] testrcs]# ci -u -m "add test1.1.1.1.h" hello.h
RCS/add test1.1.1.1.h,v <-- add test1.1.1.1.h
ci: add test1.1.1.1.h: No such file or directory
RCS/hello.h,v <-- hello.h
new revision: 1.1.1.2; previous revision: 1.1.1.1
done
[[email protected] testrcs]#
[[email protected] testrcs]# co -l -r1.1.1.1 hello.h
RCS/hello.h,v --> hello.h
revision 1.1.1.1 (locked)
done
[[email protected] testrcs]# vi hello.h
[[email protected] testrcs]# rcsdiff hello.h
===================================================================
RCS file: RCS/hello.h,v
retrieving revision 2.2
diff -r2.2 hello.h
2,4c2,3
< #include <string.h>
< #include "test.h"
< #include "test2.1.h"
---
> #include "test1.1.h"
> #include "test1.1.1.1.branch.h"
[[email protected] testrcs]# ci -u -m "1.1.1.1 branch" hello.h
RCS/1.1.1.1 branch,v <-- 1.1.1.1 branch
ci: 1.1.1.1 branch: No such file or directory
RCS/hello.h,v <-- hello.h
new revision: 1.1.1.1.1.1; previous revision: 1.1.1.1
done
[[email protected] testrcs]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
rlog确认详细信息
[[email protected] testrcs]# rlog hello.h
RCS file: RCS/hello.h,v
Working file: hello.h
head: 2.2
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 8; selected revisions: 8
description:
initial version
----------------------------
revision 2.2
date: 2016/08/15 22:13:25; author: root; state: Exp; lines: +1 -0
*** empty log message ***
----------------------------
revision 2.1
date: 2016/08/15 22:10:19; author: root; state: Exp; lines: +1 -0
modify for 2.0
----------------------------
revision 2.0
date: 2016/08/15 22:07:41; author: root; state: Exp; lines: +0 -0
*** empty log message ***
----------------------------
revision 1.2
date: 2016/08/15 22:03:45; author: root; state: Exp; lines: +1 -0
add string.h
----------------------------
revision 1.1
date: 2016/08/15 21:47:54; author: root; state: Exp;
branches: 1.1.1;
Initial revision
----------------------------
revision 1.1.1.2
date: 2016/08/15 22:31:13; author: root; state: Exp; lines: +1 -0
*** empty log message ***
----------------------------
revision 1.1.1.1
date: 2016/08/15 22:15:10; author: root; state: Exp; lines: +1 -0
branches: 1.1.1.1.1;
*** empty log message ***
----------------------------
revision 1.1.1.1.1.1
date: 2016/08/15 22:32:27; author: root; state: Exp; lines: +1 -0
*** empty log message ***
=============================================================================
[[email protected] testrcs]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
rlog -h 则可以单独列出symbolicnames等信息
[[email protected] testrcs]# rlog -h hello.h
RCS file: RCS/hello.h,v
Working file: hello.h
head: 2.2
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 8
=============================================================================
[[email protected] testrcs]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
修改注释 rcs -m
修正前rlog信息
revision 1.1
date: 2016/08/15 21:47:54; author: root; state: Exp;
branches: 1.1.1;
Initial revision
- 1
- 2
- 3
- 4
[root@host31 testrcs]# rcs -m1.1:"initial version" hello.h
RCS file: RCS/hello.h,v
done
[root@host31 testrcs]#
- 1
- 2
- 3
- 4
修正后rlog信息
revision 1.1
date: 2016/08/15 21:47:54; author: root; state: Exp;
branches: 1.1.1;
initial version
- 1
- 2
- 3
- 4
注意:-m和版本之间不能有空格等细小的事项
管理symbolic names: rcs -n
为什么要用symbolic names,很简单,作tag。使用方便的管理工具的时候你可能不会意识到版本管理工具替你做了什么,但是用RCS,需要一个文件一个文件的设定上tag,无论什么样的版本管理工具,他们都应该是类似,有一种特定的方法将某一时间断面的所有文件进行整体管理。现代的版本管理工具不会让你如此麻烦,但同时也拿去了我们了解其实际运作的机会。
[[email protected] testrcs]# rcs -nNewBranch:1.1.1.1.1.1 hello.h
RCS file: RCS/hello.h,v
done
[[email protected] testrcs]# rlog -h hello.h
RCS file: RCS/hello.h,v
Working file: hello.h
head: 2.2
branch:
locks: strict
access list:
symbolic names:
NewBranch: 1.1.1.1.1.1
keyword substitution: kv
total revisions: 8
=============================================================================
[[email protected] testrcs]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
删除symbolic names
[[email protected] testrcs]# rcs -nNewBranch hello.h
RCS file: RCS/hello.h,v
done
[[email protected] testrcs]# rcs -h hello.h
rcs: unknown option: -h
[[email protected] testrcs]# rlog -h hello.h
RCS file: RCS/hello.h,v
Working file: hello.h
head: 2.2
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 8
=============================================================================
[[email protected] testrcs]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
注意事项:-nname:rev 的版本如果不存在的时候会出错,注意空格
删除版本 rcs -o
删除1.1.1.1.1.1这个很闹心的版本
[root@host31 testrcs]# rcs -o1.1.1.1.1.1 hello.h
RCS file: RCS/hello.h,v
deleting revision 1.1.1.1.1.1
done
[root@host31 testrcs]#
- 1
- 2
- 3
- 4
- 5
除了指定版本删除,还有可以指定from和to的一定范围的删除方式
方式 | 详细说明 |
---|---|
rev1:rev2 | 从rev1删到rev2 |
rev1: | 删除rev1开始的分支所有版本 |
:rev2 | 删除到rev2的所有版本 |
此操作无比凶险,执行之前务必保存好,v文件以便恢复
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow
以上是关于版本管理 RCS之命令基础篇的主要内容,如果未能解决你的问题,请参考以下文章