📄 ch20_14.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 20] 20.14 RCS Basics </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly & Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly & Associates, Inc."><METANAME="DC.date"CONTENT="1998-10-23T15:45:05Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch20_01.htm"TITLE="20. Backing Up Files"><LINKREL="prev"HREF="ch20_13.htm"TITLE="20.13 SCCS Basics "><LINKREL="next"HREF="ch20_15.htm"TITLE="20.15 List RCS Revision Numbers with rcsrevs "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch20_13.htm"TITLE="20.13 SCCS Basics "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 20.13 SCCS Basics "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 20<BR>Backing Up Files</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch20_15.htm"TITLE="20.15 List RCS Revision Numbers with rcsrevs "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 20.15 List RCS Revision Numbers with rcsrevs "BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-6240">20.14 RCS Basics </A></H2><TABLECLASS="para.programreference"BORDER="1"><TR><THVALIGN="TOP"><ACLASS="programreference"HREF="examples/index.htm"TITLE="rcs">rcs</A><BR></TH><TDVALIGN="TOP">[I've patterned this article after<SPANCLASS="link">the article on SCCS (<ACLASS="linkend"HREF="ch20_13.htm"TITLE="SCCS Basics ">20.13</A>)</SPAN>by Bruce Barnett.<ACLASS="indexterm"NAME="UPT-ART-6240-IX-RCS"></A>This one shows how to do the same things with the Revision ControlSystem, RCS, which is on many systems - and also on the CD-ROM.-JP]</TD></TR></TABLE><PCLASS="para">You don't need to ask the system manager to restore files.You can recover any version you want with one command.Here is a simple introduction to RCS.</P><OLCLASS="orderedlist"><LICLASS="listitem"><PCLASS="para">Create a subdirectory called<EMCLASS="emphasis">RCS</EM>in the directory where you keep the code or other text filesyou want to protect.</P></LI><LICLASS="listitem"><PCLASS="para">It's a good idea (but not required) to add the characters<CODECLASS="literal">$Id$</CODE>somewhere in the file you want to place under RCS.Put this in a comment field. That is, use<CODECLASS="literal">/* $Id$ */</CODE>in a C program and<CODECLASS="literal"># $Id$</CODE>in a shell or Perl script.</P></LI><LICLASS="listitem"><PCLASS="para">Place the file under Revision Control. This is done by typing:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>ci</B></CODE> <CODECLASS="replaceable"><I>filename</I></CODE></PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-22777"></A>The <EMCLASS="emphasis">ci</EM> (checkin) program will prompt you for a short description of the file.That's it. You're done.There is another command and an option you need to know:<ACLASS="indexterm"NAME="AUTOID-22780"></A></P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>co</B></CODE> <CODECLASS="replaceable"><I>filename</I></CODE>% <CODECLASS="userinput"><B>co -l</B></CODE> <CODECLASS="replaceable"><I>filename</I></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">The <EMCLASS="emphasis">co</EM> (checkout) command will get a copy of the file from RCS.The file will be marked read-only.If you want to edit the file, use the <EMCLASS="emphasis">co -l</EM> command (the optionis a lowercase L)-then,when you're done, return the file to the <EMCLASS="emphasis">RCS</EM> directory with the command<EMCLASS="emphasis">ci</EM>.When you check in the file, <EMCLASS="emphasis">ci</EM> asks for a brief descriptionof your changes.These can be very useful, later, to learn the history of revisions andto find a particular revision you might want to recover; the command<CODECLASS="literal">rlog</CODE><CODECLASS="replaceable"><I> filename</I></CODE> gives that info.</P></LI></OL><PCLASS="para">There are only two more commands that you will need to know.If you checked out a file for editing, and later on decided you didn'twant to change it, use:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>rcs -u</B></CODE> <CODECLASS="replaceable"><I>filename</I></CODE>% <CODECLASS="userinput"><B>rm</B></CODE> <CODECLASS="replaceable"><I>filename</I></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">and if you want a list of all files currently checked out, use:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>rlog -L -R RCS/*</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">(If you don't use RCS often, you may want to store those command linesin<SPANCLASS="link">aliases or shell functions (<ACLASS="linkend"HREF="ch10_01.htm#UPT-ART-4930"TITLE="Creating Custom Commands ">10.1</A>)</SPAN>with names like <EMCLASS="emphasis">Checkout</EM>,<EMCLASS="emphasis">Checkedout</EM>, and so on.)That's all there is to it!If you are not using RCS or SCCS, you should.They are the best way to protect yourself and do not require dozens oftapes.</P><PCLASS="para">It is much easier to just type:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>co -r1.12</B></CODE> <CODECLASS="replaceable"><I>filename</I></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">One command, and version 1.12 is restored.If it's not the right one, restore the version before or after the oneyou just grabbed.(If you don't want to create a file, you can add the <EMCLASS="emphasis">-p</EM> option tosend the file to standard output.Pipe the <EMCLASS="emphasis">co</EM> output to another program: a pager, a printer, etc.)</P><PCLASS="para">If you are worried that you are keeping 12 versionsof the file on the disk, and that this will use up a lot of diskspace, don't. RCS stores the differences between versions, not 12separate copies of the file.It can recover any version of the file.</P><PCLASS="para">Suppose you delete a file by accident?Well, if the file is just checked out with a <EMCLASS="emphasis">co</EM>,it will be retrieved and marked read-only, so deleting the file will cause <EMCLASS="emphasis">rm</EM>to ask you for confirmation.If you do delete it, you can recover it with another<EMCLASS="emphasis">co</EM>command.Suppose you check out a file with <EMCLASS="emphasis">co -l</EM>,because you planned to change it.Well, if this file gets deleted accidentally, you would lose the mostrecent changes. This is why you should check your files back into RCSfrequently - several times a day or even more.Do it whenever you make significant changes to the file, and it wouldbe difficult to remember all of the changes. Making hundreds ofchanges to a file without checking it back into the system is justbegging for trouble.</P><PCLASS="para">This brief overview left out a lot of features and helpful information.For example, RCS can:</P><ULCLASS="itemizedlist"><LICLASS="listitem"><PCLASS="para">Merge two or more peoples' work into one with <EMCLASS="emphasis">rcsmerge</EM> and<EMCLASS="emphasis">co -j</EM>.</P></LI><LICLASS="listitem"><PCLASS="para">Build a tree of revisions with multiple branches and sub-branches.This lets you make and store multiple independent revisions.</P></LI><LICLASS="listitem"><PCLASS="para">Assign an arbitrary `state' to each revision - for example,<EMCLASS="emphasis">alpha</EM>, <EMCLASS="emphasis">released</EM>, <EMCLASS="emphasis">stable</EM>.</P></LI><LICLASS="listitem"><PCLASS="para">Name each revision, refer to revisions by name instead of number.</P></LI><LICLASS="listitem"><PCLASS="para">Keep a list of users who are allowed to manipulate a particularRCS file.</P></LI></UL><PCLASS="para">To find out more, see the RCS manual pages.<EMCLASS="emphasis">rcsintro</EM>(1) gives a more complete overview; manpages like<EMCLASS="emphasis">ci</EM>(1) have details on the many other useful features.Finally, O'Reilly & Associates' <EMCLASS="emphasis">Applying RCS and SCCS</EM> is packedwith tips and techniques for using revision control in group projects(where you'll need it even more).Articles<ACLASS="xref"HREF="ch27_10.htm"TITLE="Search RCS Files with rcsgrep ">27.10</A>and<ACLASS="xref"HREF="ch20_15.htm"TITLE="List RCS Revision Numbers with rcsrevs ">20.15</A>explain tools for searching RCS files.The script in article<ACLASS="xref"HREF="ch25_05.htm"TITLE="Page Through Compressed, RCS, Unprintable Files ">25.5</A>,<EMCLASS="emphasis">rcsmore</EM> (and <EMCLASS="emphasis">rcsless</EM> and <EMCLASS="emphasis">rcspg</EM>),makes it easy to read through RCS files.</P><ACLASS="indexterm"NAME="AUTOID-22852"></A><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JP</SPAN>, <SPANCLASS="authorinitials">BB</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch20_13.htm"TITLE="20.13 SCCS Basics "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 20.13 SCCS Basics "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch20_15.htm"TITLE="20.15 List RCS Revision Numbers with rcsrevs "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 20.15 List RCS Revision Numbers with rcsrevs "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">20.13 SCCS Basics </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">20.15 List RCS Revision Numbers with rcsrevs </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed & awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -