If you've been reading this book chapter by chapter, from start to finish, you should by now have acquired enough knowledge to use the Subversion client to perform the most common version control operations. You understand how to check out a working copy from a Subversion repository. You are comfortable with submitting and receiving changes using the svn commit and svn update functions. You've probably even developed a reflex that causes you to run the svn status command almost unconsciously. For all intents and purposes, you are ready to use Subversion in a typical environment.
But the Subversion feature set doesn't stop at “common version control operations.” It has other bits of functionality besides just communicating file and directory changes to and from a central repository.
This chapter highlights some of Subversion's features that, while important, aren't part of the typical user's daily routine. It assumes that you are familiar with Subversion's basic file and directory versioning capabilities. If you aren't, you'll want to first read 第 1 章 基本概念 and 第 2 章 基本使用. Once you've mastered those basics and consumed this chapter, you'll be a Subversion power user!
As we described in “修订版本”一节, revision numbers in Subversion are pretty straightforward—integers that keep getting larger as you commit more changes to your versioned data. Still, it doesn't take long before you can no longer remember exactly what happened in each and every revision. Fortunately, the typical Subversion workflow doesn't often demand that you supply arbitrary revisions to the Subversion operations you perform. For operations that do require a revision specifier, you generally supply a revision number that you saw in a commit email, in the output of some other Subversion operation, or in some other context that would give meaning to that particular number.
But occasionally, you need to pinpoint a moment in time for which you don't already have a revision number memorized or handy. So besides the integer revision numbers, svn allows as input some additional forms of revision specifiers: revision keywords and revision dates.
当用来指定修订版本范围时,不同形式的Subversion修订版本可以混合匹配。例如,你可以REV1
是修订版本关键字,REV2
是修订版本号,或者是REV1
是日期,而REV2
是修订版本关键字,等等。不同的修订版本指定符是等价的,所以你可以在冒号两边任意使用。
The Subversion client understands a number of revision
keywords. These keywords can be used instead of integer
arguments to the --revision
(-r
) option, and are resolved into specific
revision numbers by Subversion:
HEAD
版本库中最新的(或者是“最年轻的”)版本。
BASE
The revision number of an item in a working copy. If the item has been locally modified, this refers to the way the item appears without those local modifications.
COMMITTED
项目最近修改的修订版本,与BASE
相同或更早。
PREV
一个项目最后修改版本之前的那个版本,技术上可以认为是COMMITTED
-1。
因为可以从描述中得到,关键字PREV
,BASE
和COMMITTED
只在引用工作拷贝路径时使用,而不能用于版本库URL,而关键字HEAD
则可以用于两种路径类型。
下面是一些修订版本关键字的例子:
$ svn diff -r PREV:COMMITTED foo.c # shows the last change committed to foo.c $ svn log -r HEAD # shows log message for the latest repository commit $ svn diff -r HEAD # compares your working copy (with all of its local changes) to the # latest version of that tree in the repository $ svn diff -r BASE:HEAD foo.c # compares the unmodified version of foo.c with the latest version of # foo.c in the repository $ svn log -r BASE:HEAD # shows all commit logs for the current versioned directory since you # last updated $ svn update -r PREV foo.c # rewinds the last change on foo.c, decreasing foo.c's working revision $ svn diff -r BASE:14 foo.c # compares the unmodified version of foo.c with the way foo.c looked # in revision 14
Revision numbers reveal nothing about the world outside
the version control system, but sometimes you need to
correlate a moment in real time with a moment in version
history. To facilitate this, the --revision
(-r
) option can also accept as input date
specifiers wrapped in curly braces ({
and
}
). Subversion accepts the standard
ISO-8601 date and time formats, plus a few others. Here are
some examples. (Remember to use quotes around any date that
contains spaces.)
$ svn checkout -r {2006-02-17} $ svn checkout -r {15:30} $ svn checkout -r {15:30:00.200000} $ svn checkout -r {"2006-02-17 15:30"} $ svn checkout -r {"2006-02-17 15:30 +0230"} $ svn checkout -r {2006-02-17T15:30} $ svn checkout -r {2006-02-17T15:30Z} $ svn checkout -r {2006-02-17T15:30-04:00} $ svn checkout -r {20060217T1530} $ svn checkout -r {20060217T1530Z} $ svn checkout -r {20060217T1530-0500} …
当你指定一个日期,Subversion会在版本库找到接近这个日期的最近版本,并且对这个版本继续操作:
$ svn log -r {2006-11-28} ------------------------------------------------------------------------ r12 | ira | 2006-11-27 12:31:51 -0600 (Mon, 27 Nov 2006) | 6 lines …
你可以使用时间段,Subversion会找到这段时间的所有版本:
$ svn log -r {2006-11-20}:{2006-11-29} …
Since the timestamp of a revision is stored as an unversioned, modifiable property of the revision (see “属性”一节), revision timestamps can be changed to represent complete falsifications of true chronology, or even removed altogether. Subversion's ability to correctly convert revision dates into real revision numbers depends on revision datestamps maintaining a sequential ordering—the younger the revision, the younger its timestamp. If this ordering isn't maintained, you will likely find that trying to use dates to specify revision ranges in your repository doesn't always return the data you might have expected.