快速指南

Please make sure your seat backs are in their full, upright position and that your tray tables are stored. Flight attendants, prepare for take-off….

这是一个非常高层次的教程,能够帮助你熟悉Subversion的基本配置和操作,在结束这个教程时,你一定能够对Subversion的典型使用有了一个基础的认识。

注意

运行下面的例子需要首先正确安装Subversion客户端程序svn以及管理工具svnadmin,并且必须为1.2或更新版本的Subversion程序(可以运行svn --version来检查Subversion的版本。)

Subversion的所有版本化数据都储存在中心版本库中。因此首先,我们需要创建一个版本库:

$ svnadmin create /var/svn/repos
$ ls /var/svn/repos
conf/  dav/  db/  format  hooks/  locks/  README.txt

This command creates a new directory, /var/svn/repos, which contains a Subversion repository. This new directory contains (among other things) a collection of database files. You won't see your versioned files if you peek inside. For more information about repository creation and maintenance, see 第 5 章 版本库管理.

Subversion has no concept of a “project.” The repository is just a virtual versioned filesystem, a large tree that can hold anything you wish. Some administrators prefer to store only one project in a repository, and others prefer to store multiple projects in a repository by placing them into separate directories. The merits of each approach are discussed in “规划你的版本库结构”一节. Either way, the repository manages only files and directories, so it's up to humans to interpret particular directories as “projects”. So while you might see references to projects throughout this book, keep in mind that we're only ever talking about some directory (or collection of directories) in the repository.

In this example, we assume that you already have some sort of project (a collection of files and directories) that you wish to import into your newly created Subversion repository. Begin by organizing your data into a single directory called myproject (or whatever you wish). For reasons explained in 第 4 章 分支与合并, your project's tree structure should contain three top-level directories named branches, tags, and trunk. The trunk directory should contain all of your data, while the branches and tags directories are empty:

/tmp/myproject/branches/
/tmp/myproject/tags/
/tmp/myproject/trunk/
                     foo.c
                     bar.c
                     Makefile
                     …

branchestagstrunk这三个子目录不是Subversion必须的。但这样做是Subversion的习惯用法,我们还是遵守这个约定吧。

准备好了数据之后,就可以使用svn import命令(参见“Getting Data into Your Repository”一节)将其导入到版本库中:

$ svn import /tmp/myproject file:///var/svn/repos/myproject -m "initial import"
Adding         /tmp/myproject/branches
Adding         /tmp/myproject/tags
Adding         /tmp/myproject/trunk
Adding         /tmp/myproject/trunk/foo.c
Adding         /tmp/myproject/trunk/bar.c
Adding         /tmp/myproject/trunk/Makefile
…
Committed revision 1.
$ 

现在版本库中已经保存了目录中的数据。如前所述,直接查看版本库是看不到文件和目录的;它们存放在数据库之中。但是版本库的虚拟文件系统中则包含了一个名为myproject的顶级目录,其中依此保存了所有的数据。

注意我们在一开始创建的那个/tmp/myproject目录并没有改变,Subversion并不在意它(事实上,完全可以删除这个目录)。要开始使用版本库数据,我们还要创建一个新的用于存储数据的“工作拷贝”,这是一个私有工作区。从Subversion版本库里“检出”一个myproject/trunk目录工作拷贝的操作如下:

$ svn checkout file:///var/svn/repos/myproject/trunk myproject
A  myproject/foo.c
A  myproject/bar.c
A  myproject/Makefile
…
Checked out revision 1.

现在,在myproject目录下生成了一个版本库数据的独立拷贝。我们可以在这个工作拷贝中编辑文件,并将修改提交到版本库中。

完整的工作拷贝操作指南,请参见第 2 章 基本使用

现在,Subversion版本库可以通过网络方式访问。参考第 6 章 服务配置,了解不同服务器软件的使用以及配置方法。