导入数据到版本库

版本库布局

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

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如何处理属性的更多信息,请阅读“项目设置”一节

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