另一个常见的版本控制系统概念是标¾(tag),一个标签只是一个项目某一时间的“快照”,在Subversion里这个概念无处不在—每一次提交的修订版本都是一个精确的快照。
However, people often want to give more human-friendly names
to tags, such as release-1.0
. And they want
to make snapshots of smaller subdirectories of the filesystem.
After all, it's not so easy to remember that release 1.0 of a
piece of software is a particular subdirectory of revision
4822.
svn copy再次登场,你希望建立一个/calc/trunk
的一个快照,就像HEAD
修订版本,建立这样一个拷贝:
$ svn copy http://svn.example.com/repos/calc/trunk \ http://svn.example.com/repos/calc/tags/release-1.0 \ -m "Tagging the 1.0 release of the 'calc' project." Committed revision 902.
This example assumes that a
/calc/tags
directory already exists. (If
it doesn't, you can create it using svn
mkdir.) After the copy completes, the new
release-1.0
directory is forever a
snapshot of how the /trunk
directory
looked in the HEAD
revision at the time you
made the copy. Of course you might want to be more precise
about exactly which revision you copy, in case somebody else
may have committed changes to the project when you weren't
looking. So if you know that revision 901 of
/calc/trunk
is exactly the snapshot you
want, you can specify it by passing -r 901
to
the svn copy command.
但是等一下:标签的产生过程与建立分支是一样的?是的,实际上在Subversion中标签与分支没有区别,都是普通的目录,通过copy命令得到,与分支一样,一个目录之所以是标签只是人们决定这样使用它,只要没有人提交这个目录,它永远是一个快照,但如果人们开始提交,它就变成了分支。
If you are administering a repository, there are two approaches you can take to managing tags. The first approach is “hands off”: as a matter of project policy, decide where your tags will live, and make sure all users know how to treat the directories they copy. (That is, make sure they know not to commit to them.) The second approach is more paranoid: you can use one of the access-control scripts provided with Subversion to prevent anyone from doing anything but creating new copies in the tags area (see 第 6 章 服务配置). The paranoid approach, however, isn't usually necessary. If a user accidentally commits a change to a tag directory, you can simply undo the change as discussed in the previous section. This is version control, after all!
有时候你希望你的“快照”能够很复杂,而不只是一个单独修订版本的一个单独目录。
For example, pretend your project is much larger than our
calc
example: suppose it contains a
number of subdirectories and many more files. In the course
of your work, you may decide that you need to create a working
copy that is designed to have specific features and bug fixes.
You can accomplish this by selectively backdating files or
directories to particular revisions (using svn update
-r liberally), by switching files and directories to
particular branches (making use of svn
switch), or even just by making a bunch of local
changes. When you're done, your working copy is a hodgepodge
of repository locations from different revisions. But after
testing, you know it's the precise combination of data you
need to tag.
是时候进行快照了,拷贝URL在这里不能工作,在这个例子里,你希望把本地拷贝的布局做镜像并且保存到版本库中,幸运的是,svn copy包括四种不同的使用方式(在第 9 章 Subversion 完全参考可以详细阅读),包括拷贝工作拷贝到版本库:
$ ls my-working-copy/ $ svn copy my-working-copy \ http://svn.example.com/repos/calc/tags/mytag \ -m "Tag my existing working copy state." Committed revision 940.
Now there is a new directory in the repository,
/calc/tags/mytag
, which is an exact
snapshot of your working copy—mixed revisions, URLs,
local changes and all.
Other users have found interesting uses for this feature. Sometimes there are situations where you have a bunch of local changes made to your working copy, and you'd like a collaborator to see them. Instead of running svn diff and sending a patch file (which won't capture directory, symlink, or property changes), you can instead use svn copy to “upload” your working copy to a private area of the repository. Your collaborator can then either check out a verbatim copy of your working copy or use svn merge to receive your exact changes.
虽然这是上传快速工作拷贝快照的一个好方法,但这不是初始创建分支的好方法。分支创建必须是它本身的事件,而这个方法创建的分支包含了额外修改,都包含在一个单独修订版本里。这让我们很难识别分支点的单个修订版本号码。