有两种方法可以将新文件引入 Subversion 版本库:svn import 和 svn add,我们将在本章讨论 svn import,而会在回顾 Subversion 的典型一天时讨论 svn add。
svn import 是将未版本化文件导入版本库的最快方法,会根据需要创建中介目录。svn import 不需要一个工作副本,你的文件会直接提交到版本库,这通常用在你希望将一组文件加入到 Subversion 版本库时,例如:
$ svn import /path/to/mytree \ http://svn.example.com/svn/repo/some/project \ -m "Initial import" Adding mytree/foo.c Adding mytree/bar.c Adding mytree/subdir Adding mytree/subdir/quux.h Committed revision 1. $
The previous example copied the contents of the local directory
mytree
into the directory
some/project
in the repository. Note that you didn't
have to create that new directory first—svn import
does that for you. Immediately after the commit, you can see your data in
the repository:
$ svn list http://svn.example.com/svn/repo/some/project bar.c foo.c subdir/ $
Note that after the import is finished, the original local directory is not converted into a working copy. To begin working on that data in a versioned fashion, you still need to create a fresh working copy of that tree.
Subversion provides the ultimate flexibility in terms of how you arrange your data. Because it simply versions directories and files, and because it ascribes no particular meaning to any of those objects, you may arrange the data in your repository in any way that you choose. Unfortunately, this flexibility also means that it's easy to find yourself “lost without a roadmap” as you attempt to navigate different Subversion repositories which may carry completely different and unpredictable arrangements of the data within them.
To counteract this confusion, we recommend that you follow a repository
layout convention (established long ago, in the nascency of the Subversion
project itself) in which a handful of strategically named Subversion
repository directories convey valuable meaning about the data they hold.
Most projects have a recognizable “main line”, or
trunk, of development; some
branches, which are divergent copies of development
lines; and some tags, which are named, stable
snapshots of a particular line of development. So we first recommend that
each project have a recognizable project root in the
repository, a directory under which all of the versioned information for
that project—and only that project—lives. Secondly, we suggest
that each project root contain a trunk
subdirectory for
the main development line, a branches
subdirectory in
which specific branches (or collections of branches) will be created, and a
tags
subdirectory in which specific tags (or
collections of tags) will be created. Of course, if a repository houses
only a single project, the root of the repository can serve as the project
root, too.
以下是一些例子:
$ svn list file:///var/svn/single-project-repo trunk/ branches/ tags/ $ svn list file:///var/svn/multi-project-repo project-A/ project-B/ $ svn list file:///var/svn/multi-project-repo/project-A trunk/ branches/ tags/ $
We talk much more about tags and branches in 第 4 章 分支与合并. For details and some advice on how to set up repositories when you have multiple projects, see 第 7.1 节 “版本库布局”. Finally, we discuss project roots more in 第 2.1 节 “规划你的版本库结构”.
Subversion 努力不限制版本控制的数据类型。文件的内容和属性值都是按照二进制数据存储和传递,并且第 4.1 节 “文件内容类型”给 Subversion 提示,以说明对于特定文件“文本化的”操作是没有意义的,也有一些地方,Subversion 对存放的信息有限制。
Subversion 内部使用二进制处理数据—例如,属性名称,路径名和日志信息— UTF-8 编码的 Unicode,这并不意味着与 Subversion 的交互必须完全使用 UTF-8。作为一个惯例,Subversion 的客户端能够透明的转化 UTF-8 和你所使用系统的编码,前提是可以进行有意义的转换(当然是大多数目前常见的编码)。
此外,路径名称在 WebDAV 交换中会作为 XML 属性值,就像 Subversion 的管理文件。这意味着路径名称只能包含合法的 XML(1.0) 字符,Subversion 也会禁止路径名称中出现 TAB, CR 或 LF 字符,所以它们才不会在区别程序或如svn log和svn status (stat, st)的输出命令中断掉。
虽然看起来要记住很多事情,但在实践中这些限制很少会成为问题。只要你的本地设置兼容 UTF-8,也不在路径名称中使用控制字符,与 Subversion 的通讯就不会有问题。命令行客户端会添加一些额外的帮助字节—自动将你输入的 URL 路径字符转化为“合法正确的”内部用版本。