第 4 章 版本库

目录

创建版本库
使用命令行工具创建版本库
使用 TortoiseSVN 创建版本库
本地访问版本库
Accessing a Repository on a Network Share
版本库备份
钩子脚本
检出链接

无论你用什么协议访问你的版本库,都至少需要创建一个版本库,这可以使用Subversion命令行客户端或TortoiseSVN完成。

如果你还没有创建Subversion版本库,是时间开始了。

创建版本库

You can create a repository with the FSFS backend or with the older Berkeley Database (BDB) format. The FSFS format is generally faster and easier to administer, and it works on network shares and Windows 98 without problems. The BDB format was once considered more stable simply because it has been in use for longer, but since FSFS has now been in use in the field for several years, that argument is now rather weak. Read Choosing a Data Store in the Subversion book for more information.

使用命令行工具创建版本库

  1. 创建一个名为SVN(例如D:\SVN\)的空文件夹,作为你的所有版本库的根。

  2. D:\SVN\里创建另一个目录MyNewRepository

  3. 打开命令行窗口(或DOS窗口),进入D:\SVN\目录,输入

    svnadmin create --fs-type bdb MyNewRepository
    

    svnadmin create --fs-type fsfs MyNewRepository
    

现在你在D:\SVN\MyNewRepository创建了一个新的版本库。

使用 TortoiseSVN 创建版本库

图 4.1. 未版本控制文件夹的 TortoiseSVN 菜单

未版本控制文件夹的 TortoiseSVN 菜单

  1. 打开资源管理器

  2. 创建一个新的文件夹,命名为SVNRepository

  3. 右键点击新创建的目录,选择TortoiseSVN在此创建版本库...

    然后就会在新文件夹创建一个版本库,不要手工编辑这些文件!!!如果你得到什么警告,一定要先确定目录非空并且没有写保护。

提示

TortoiseSVN 不再给你创建 BDB 版本库的选择,尽管你仍旧可以使用命令行工具创建。FSFS 版本库通常很容易维护,也让我们维护 TortoiseSVN 变得更容易,因为我们不再需要处理不同 BDB 版本之间的兼容性问题。

由于这些兼容性问题,将来的 TortoiseSVN 不再支持使用 file:/// 访问 BDB 版本库,尽管我们继续支持使用 svn://http://http:// 协议访问 BDB 版本库。因此,我们强烈建议任何新的必须使用 file:/// 协议访问的版本库使用 FSFS 格式。

当然除了本地测试之外,我们也建议你根本不要使用 file:/// 协议访问。除非是单个开发人员,使用服务器模型更为安全可靠。

本地访问版本库

为了访问本地版本库,你需要这个文件夹的路径,只要记住Subversion期望所有的版本库路径使用的形式为file:///C:/SVNRepository/,请注意全部使用的是斜杠。

为了访问网络共享中的版本库,你可以使用驱动器影射或使用UNC路径,对于UNC路径,形式为file://ServerName/path/to/repos/,请注意这里前面只有两个斜杠。

在SVN 1.2之前,UNC路径曾经是一种非常晦涩的格式file:///\ServerName/path/to/repos,这种格式依然支持,但不推荐。

警告

Do not create or access a Berkeley DB repository on a network share. It cannot exist on a remote file system. Not even if you have the network drive mapped to a drive letter. If you attempt to use Berkeley DB on a network share, the results are unpredictable - you may see mysterious errors right away, or it may be months before you discover that your repository database is subtly corrupted.

Accessing a Repository on a Network Share

Although in theory it is possible to put a FSFS repository on a network share and have multiple users access it using file:/// protocol, this is most definitely not recommended. In fact we would strongly discourage it, and do not support such use.

Firstly you are giving every user direct write access to the repository, so any user could accidentally delete the entire repository or make it unusable in some other way.

Secondly not all network file sharing protocols support the locking that Subversion requires, so you may find your repository gets corrupted. It may not happen straight away, but one day two users will try to access the repository at the same time.

Thirdly the file permissions have to be set just so. You may just about get away with it on a native Windows share, but SAMBA is particularly difficult.

file:/// access is intended for local, single-user access only, particularly testing and debugging. When you want to share the repository you really need to set up a proper server, and it is not nearly as difficult as you might think. Read 第 3 章 配置服务器 for guidelines on choosing and setting up a server.