Chinaunix首页 | 论坛 | 博客
  • 博客访问: 65521
  • 博文数量: 14
  • 博客积分: 1599
  • 博客等级: 上尉
  • 技术积分: 160
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-13 09:39
文章分类
文章存档

2011年(6)

2010年(4)

2008年(4)

分类: 系统运维

2010-03-18 17:09:18

以前一直用cvs或是svn在做版本管理,但是这些工具对于个别的文件的版本管理而言就显得有些臃肿和庞大。比如在UNIX下管理几个配置文件。

而RCS(Revision Control System)就显得轻便了很多,使用也非常方便。

比如在当前目录下有一个配置文件/home/me/a.conf需要管理历史版本。

[root@wl00070019 rcstst]# touch a.conf
[root@wl00070019 rcstst]# ls
a.conf
[root@wl00070019 rcstst]# more a.conf
[root@wl00070019 rcstst]# ls
a.conf
[root@wl00070019 rcstst]# mkdir RCS
[root@wl00070019 rcstst]# ci a.conf
RCS/a.conf,v  <--  a.conf
enter description, terminated with single '.' or end of file:
NOTE: This is NOT the log message!
>> init version
>> .
initial revision: 1.1
done
[root@wl00070019 rcstst]# ls
RCS
[root@wl00070019 rcstst]# co -l a.conf
RCS/a.conf,v  -->  a.conf
revision 1.1 (locked)
done
[root@wl00070019 rcstst]# echo line1 >a.conf
[root@wl00070019 rcstst]# ci a.conf
RCS/a.conf,v  <--  a.conf
new revision: 1.2; previous revision: 1.1
enter log message, terminated with single '.' or end of file:
>> add line a
>> .
done
[root@wl00070019 rcstst]# ls
RCS
[root@wl00070019 rcstst]# co a.conf
RCS/a.conf,v  -->  a.conf
revision 1.2
done
[root@wl00070019 rcstst]# echo lineb >>a.conf
[root@wl00070019 rcstst]# rcsdiff a.conf
===================================================================
RCS file: RCS/a.conf,v
retrieving revision 1.2
diff -r1.2 a.conf
1a2
> lineb
[root@wl00070019 rcstst]#

使用上和cvs于svn区别不大,更适合于对单个文件的版本管理。

而rcsdiff的输出格式和diff的输出也类似,以前关注过diff的格式,但是没有记得太清楚。
找到官网重新学习一下。

%20Normal

Detailed Description of Normal Format

The normal output format consists of one or more hunks of differences; each hunk shows one area where the files differ. Normal format hunks look like this: 

通常输出格式包含一块或多块不同,每一块显示文件不同的区域,看起来就像这样。

change-command
< from-file-line
< from-file-line...
---

> to-file-line
> to-file-line...

There are three types of change commands. Each consists of a line number or comma-separated range of lines in the first file, a single character indicating the kind of change to make, and a line number or comma-separated range of lines in the second file. All line numbers are the original line numbers in each file. The types of change commands are:

修改命令有三种类型,每个类型的命令包含第一个文件的行或点分的行范围,一个单字符表示修改的类型,第二个文件的行或者行的范围。所有的行号使用的是在每个文件中的原始的行号。修改命令类型如下:

la
Add the lines in range r of the second file after line l of the first file. For example, 8a12,15 means append lines 12-15 of file 2 after line 8 of file 1; or, if changing file 2 into file 1, delete lines 12-15 of file 2.

(添加)将第二个文件中的范围中的行添加到第一个文件的行,例如: 8a12,15 意思是将第二个文件的12-15行添加到第一个文件(l)的第8行之后。或者说,如果将文件2改为文件1,需要将文件2的12-15行删除。 

fct
Replace the lines in range f of the first file with lines in range t of the second file. This is like a combined add and delete, but more compact. For example, 5,7c8,10 means change lines 5-7 of file 1 to read as lines 8-10 of file 2; or, if changing file 2 into file 1, change lines 8-10 of file 2 to read as lines 5-7 of file 1. 
          
(修改)将第一个文件中f范围的行替换为第二个文件中的范围为t的行。这就像一个添加和删除的组合,但是更为简洁。例 如:5,7c8,10 意思是将文件1的5-7行替换为第二个文件的8-10行,反过来,将第二个文件的8-10行替换为第一个文件的5-7行,可以让文件2于文件1相同。
rdl
Delete the lines in range r from the first file; line l is where they would have appeared in the second file had they not been deleted. For example, 5,7d3 means delete lines 5-7 of file 1; or, if changing file 2 into file 1, append lines 5-7 of file 1 after line 3 of file 2.
          (删除)从第一个文件中删除范围为r的行;行l是[明白意思,不知道咋说],例如:5,7d3的意思是将文件1中的5-7行删除,反过来如果要让文件2和文件1相同则将文件1中的5-7行添加到第3行之后。

以上为normal模式,另外其他几种模式,但是用的最多的应该还是normal和sidebyside模式。
  • : Showing differences without surrounding text.
  • : Showing differences with the surrounding text.
  • : Showing differences in two columns.
  • : Generating scripts for other programs.
  • : Merging files with if-then-else.
Sidebyside模式相对比较直观。
%20Side%20by%20Side

两栏中间位通过一些特殊的字符来表示关系。
white space
The corresponding lines are in common. That is, either the lines are identical, or the difference is ignored because of one of the --ignore options。什么都没有表示两边内容相同或者被忽略了不同。
|
The corresponding lines differ, and they are either both complete or both incomplete. 
       
<
The files differ and only the first file contains the line. 
           文件不同,并且只有第一个文件包含该行。
>
The files differ and only the second file contains the line. 
          文件不同,并且只有第二个文件包含该行。
(
Only the first file contains the line, but the difference is ignored. 
          仅第1个文件包含该行,但是区别被忽略。
)
Only the second file contains the line, but the difference is ignored. 
           仅第2个文件包含该行,但是区别被忽略。
\
The corresponding lines differ, and only the first line is incomplete.
/
The corresponding lines differ, and only the second line is incomplete.


例子:

This is the file lao:

The Way that can be told of is not the eternal Way;
The name that can be named is not the eternal name.
The Nameless is the origin of Heaven and Earth;
The Named is the mother of all things.
Therefore let there always be non-being,
so we may see their subtlety,
And let there always be being,
so we may see their outcome.
The two are the same,
But after they are produced,
they have different names.

This is the file tzu:

The Nameless is the origin of Heaven and Earth;
The named is the mother of all things.

Therefore let there always be non-being,
so we may see their subtlety,
And let there always be being,
so we may see their outcome.
The two are the same,
But after they are produced,
they have different names.
They both may be called deep and profound.
Deeper and more profound,
使用diff lao tuz

1,2d0
< The Way that can be told of is not the eternal Way;
< The name that can be named is not the eternal name.
4c2,3
< The Named is the mother of all things.
---
> The named is the mother of all things.
>
11a11,13
> They both may be called deep and profound.
> Deeper and more profound,
> The door of all subtleties!
1,2d0 将第一个文件的1-2行删除
4c2,3 将第一个文件的第4行改为第二个文件的2,3行
11a11,13将第二个文件的11-13行加到第一个文件的11行之后。

有很多图形化的工具可以让这样的修改更为形象化,如windiff,notepad++等,或者online的形式
以下是side2side和inline两种形式的比较结果。

阅读(1318) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~