导入数据到版本库

版本库布局

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

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可以将它们移动或重命名。

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

所以,如果你还没创建一个基本的文件夹结构到你的版本库中,你现在可以这样做:

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

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

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

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

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

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

/trunk
/branches
/tags

你还可以使用版本库浏览器直接在版本库中创建文件夹。

导入

在将你的项目导入到版本库之前,你应该:

  1. 删除所有构建工程不需要的文件(临时文件,编译器产生的文件,例如 *.obj,生成的二进制文件,...)

  2. Organize the files in folders and sub-folders. Although it is possible to rename/move files later it is highly recommended to get your project's structure straight before importing!

现在进入资源管理器,选择你的项目的顶层目录,右击打开上下文菜单。选择命令TortoiseSVN导入 ...,它会弹出一个对话框:

图 5.6. 导入对话框

导入对话框


在这个对话框中,输入你的项目导入到版本库的URL。

这个输入信息将用作提交日志。

默认情况下,匹配全局忽略模式的文件和文件夹不会被导入。你可以使用包含忽略文件检验栏来禁止此行为。参考“常规设置”一节以获得关于全局忽略模式的更多信息。

当你点击确认时,TortoiseSVN 会导入包含所有文件的完整目录树到版本库。如前所述,你导入的文件夹名称不会在版本库中出现,只有这个文件夹的内容会在版本库中出现。现在这个工程就存贮在版本库,被版本控制。请注意,你导入的文件夹没有被版本控制!你需要检出刚才导入的版本,以便获得受版本控制的工作目录。或者继续阅读,找到如何导入文件夹到合适的位置。

导入适当的位置

Subversion 导入命令功能有限 - 你不能容易的选择导入的项目。而且,你导入的文件夹不会成为 Subversion 工作副本 - 你不得不单独做检出。但是不要担心,有其它方法克服这些缺陷 :-)

假定你已经有个版本库,你想给它增加一个新目录结构,只需以下步骤:

  1. 使用版本库浏览器直接在版本库中创建项目文件夹。

  2. 在你要导入的文件夹检出新目录。你会得到一个本地目录为空的警告。现在你有一个版本控制的顶级目录,含有未版本控制的内容。

  3. 在此受版本控制的文件夹上使用TortoiseSVN增加...增加部分或全部内容。你可以增加或删除文件,在文件夹上设置svn:ignore属性,或者你需要的其它修改。

  4. 提交顶级目录,你有一个新的版本树,一份从你已有目录创建的本地工作副本。

专用文件

有时候你需要版本控制一个包含用户专用的数据。它意味着你有一个文件,每个开发者/用户都需要修改,一边满足他/她的本地配置。但是版本控制这样的文件是困难的,因为每个用户可能都要提交他/她的修改。

In such cases we suggest to use template files. You create a file which contains all the data your developers will need, add that file to version control and let the developers check this file out. Then, each developer has to make a copy of that file and rename that copy. After that, modifying the copy is not a problem anymore.

作为例子,你可以看看TortoiseSVN的构建脚本。它调用一个TortoiseVars.bat文件,它并不在版本库中。 只有TortoiseVars.tmpl在版本库中。TortoiseVars.tmpl是一个模版文件,每个开发者都需要创建一个副本,改名为TortoiseVars.bat。在这个文件中,我们增加了注释,所以用户知道他们需要编辑那些行,以便适应他们的本地配置,使其能工作。

于是为了不干扰用户,我们也将TortoiseVars.bat增加到它的父目录的忽略列表,也就是,我们设置了Subversion属性svn:ignore包含这个文件名称。这样,每次提交时它都不会作为没有版本控制的文件出现。

引用的工程

有时候,构建一个需要不同检出的工作目录是很有用的。举例来说,你需要不同的子目录来自版本库的不同位置。,或者可能完全来自不同的版本库。如果你需要每个用户具有相同的目录结构,你可以定义svn:externals属性。

Let's say you check out a working copy of /project1 to D:\dev\project1. Select the folder D:\dev\project1, right click and choose Windows MenuProperties from the context menu. The Properties Dialog comes up. Then go to the Subversion tab. There, you can set properties. Click Add.... Select the svn:externals property from the combobox and write in the edit box the repository URL in the format name url or if you want to specify a particular revision, name -rREV url You can add multiple external projects, 1 per line. Note that URLs must be properly escaped or they will not work properly. For example you must replace each space with %20. Note that it is not possible to use folder names with spaces in them. Suppose that you have set these properties on D:\dev\project1:

sounds   http://sounds.red-bean.com/repos
quick_graphs  http://graphics.red-bean.com/repos/fast%20graphics
skins/toolkit -r21 http://svn.red-bean.com/repos/skin-maker

Now click Set and commit your changes. When you (or any other user) update your working copy, Subversion will create a sub-folder D:\dev\project1\sounds and checkout the sounds project, another sub-folder D:\dev\project1\quick graphs containing the graphics project, and finally a nested sub-folder D:\dev\project1\skins\toolkit containing revision 21 of the skin-maker project.

提示

You should strongly consider using explicit revision numbers in all of your externals definitions, as described above. Doing so means that you get to decide when to pull down a different snapshot of external information, and exactly which snapshot to pull. Besides the common sense aspect of not being surprised by changes to third-party repositories that you might not have any control over, using explicit revision numbers also means that as you backdate your working copy to a previous revision, your externals definitions will also revert to the way they looked in that previous revision, which in turn means that the external working copies will be updated to match they way they looked back when your repository was at that previous revision. For software projects, this could be the difference between a successful and a failed build of an older snapshot of your complex code base.

如果一个外部工程位于同一版本库中,当你向主项目提交你的修改时,你对外部工程做的修改也会包含在提交列表中。

如果外部工程位于不同的版本库,当你向主项目提交你的修改时,你对外部工程做的修改会被通报,但是你必须单独的提交这些外部项目的修改。

Note that if you change the URL in an svn:externals property, then next time you update your working copy Subversion will delete the old external folder and make a fresh checkout, so you will see files being Added, rather than being Updated as you might have expected. This situation might occur if you reference a tag from another project. When a new version of that project is released, you change your external reference to point to the new tag.

外部定义svn:externals中的URL是绝对路径。如果你重新定位工作副本,或者外部版本库重新定位了,这些URL不会自动更新。而且,如果你分支了一个工程,它的外部定义位于同一版本库中,分支中的这些URL也不会更新;你可能需要用对分支的引用替换对最新版本的引用。

如果你需要TortoiseSVN如何处理属性的更多信息,请阅读“项目设置”一节

如果你需要知道存取公共子个我我你工程的不同方法,请阅读“包含一个普通的子项目”一节.