创建版本库

Posted on Posted in 5.版本库

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

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

创建版本库

你可以使用
 FSFS 或较老的 Berkeley 数据库(BDB)作为版本库的后端,FSFS
 格式通常更快一点,还容易管理,而且可以正常运行在网络共享磁盘上 或 Windows 98 中。BDB
 格式曾经简单的被认为更加稳定,因为其经过了更长时间的验证,但是既然 FSFS 已经使用了几年,这个论据已经相当不牢固了。参考
 Subversion 手册的 选择数据存储 以获得更多信息。

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

  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 版本之间的兼容性问题。

Future versions of TortoiseSVN will not support file://
 access to BDB repositories due to these compatibility issues, although
 it will of course always support this repository format when accessed
 via a server through the svn://, http:// or https:// protocols. For this reason, we strongly recommend that any new repository which must be accessed using file:// protocol is created as FSFS.

Of course we also recommend that you don't use file://
 access at all, apart from local testing purposes. Using a server is
 more secure and more reliable for all but single-developer use.

本地访问版本库

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

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

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

警告

不要创建和访问网络共享上的 Berkeley DB 版本库。它不能存在于远程文件系统。即使是映射到盘符的共享。如果你尝试在网络共享使用 Berkeley DB,结果难以预料 - 你可能会立刻看到奇怪的错误,也有可能几个月之后才发现数据库已经损坏了。

访问网络共享磁盘上的版本库

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.

版本库布局

在将你的数据导入到版本库之前,首先你得考虑如何组织你的数据。如果你使用一种推荐的布局,你在后面的操作将会更容易许多。

There are some standard, recommended ways to organize a repository. Most people create a trunk directory to hold the “main line” of development, a branches directory to contain branch copies, and a tags directory to contain tag copies. If a repository holds only one project, then often people create these top-level directories:

/trunk /branches /tags

如果一个版本库包含多个项目,人们通常按分支来安排布局:

/trunk/paint /trunk/calc /branches/paint /branches/calc /tags/paint /tags/calc

……或者按项目:

/paint/trunk /paint/branches /paint/tags /calc/trunk /calc/branches /calc/tags

如果项目不是密切相关,而且每一个是单独被检出,那么按项目布局是合理的。对于那些你想一次检出所有项目,或需要将它们打成一个分发包的相关项目,按分支来布局通常比较好。这种方式你只要检出一个分支,而且子项目之间的关系也比较清楚。

如果你采用顶层/trunk /tags /branches这种方式,并不意味着你必须复制整个主线为分支或标签,而且某些情况下这种结构更具灵活性。

对于不相关的项目,你可能更愿意使用不同的版本库。当你提交时,改变的是整个版本库的修订号,而不是项目的。让两个不相关的项目共用一个版本库,会导致修订号出现较大的跳跃。Subversion和TortoiseSVN项目看起来是在同一个主机地址,但是它们是在完全独立的版本库中开发着,并且版本号也不相干。

当然,你完全可以不理会上面提及的通用布局。你可以自由改变,来满足你和你团队的需要。请记住,不管你选择哪种布局,它都不是永久的。你可以在随时重新组织你的版本库。因为分支和标签是普通的目录,只要你愿意,TortoiseSVN可以将它们移动或重命名。

从一种布局转换到另一种布局仅仅是在服务器端移动一些文件或目录;如果你不喜欢版本库的组织形式,仅管大胆地修改那些目录。

So
 if you haven't already created a basic folder structure inside your
 repository you should do that now. There are two ways to achieve this.
 If you simply want to create a /trunk /tags /branches  structure, you can use the repository browser to create the three
 folders (in three separate commits). If you want to create a deeper
 hierarchy then it is simpler to create a folder structure on disk first
 and import it in a single commit, like this:

  1. 在你的硬盘上创建一个空的文件夹

  2. 在那个文件夹下创建你想要的顶级目录--千万不要放任何文件进去!

  3. 通过在那个文件夹右键,选择TortoiseSVN → 导入… 将这个结构导入到版本库中。这将导入临时文件夹到版本库的根目录形成一个基本的版本库布局。

注意,你所导入的那个文件夹的名字并不存在于版本库中,仅仅是它所包含的内容。比如,创建如下结构的文件夹

C:\Temp\New\trunk C:\Temp\New\branches C:\Temp\New\tags

导入C:\Temp\New到版本库的根目录,版本库中将会是这样:

/trunk /branches /tags