外部条目

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

外部文件夹

比方说您检出了一个 /project1 工作副本到 D:\dev\project1。选择文件夹 D:\dev\project1右击 该文件夹并从上下文菜单中选择 Windows 菜单属性。属性对话框出现。然后转到 Subversion 选项卡。在那里您可以设置属性。单击 属性...。在属性对话框中,即可以双击 svn:externals 如果它已经存在,或点击 新建... 按钮并从菜单中选择 externals。要添加新的外部项目,单击 新建...,然后在显示的对话框中填写所需的信息。

小心

URLs 必须正确转义否则将不会工作,例如必须将每个空格替换为 %20

如果你需要在本地路径中包含空格或其它特殊字符,你可以使用双引号将它们括起来,或者你可以使用 Unix shell 风格的转义字符 -- 在特殊字符前添加 \ (反斜线)。当然这样就意味着你必须使用 / (正斜线)作为路径的分隔符。注意:这一特性是在 Subversion 1.6 中新引入的,不支持旧版本的客户端程序。

使用确定的版本号

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 the 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.

The edit dialog for svn:externals properties allows you to select the externals and automatically set them explicitly to the HEAD revision.

如果外部项目位于同一版本库,当你提交你的主要项目时,你在这儿所做的任何更改都将包含在提交列表中。

If the external project is in a different repository, any changes you make to the external project will be shown or indicated when you commit the main project, but you have to commit those external changes separately.

如果你在 svn:externals 定义中使用绝对 URL 并且你不得不重定位你的工作副本(例如,版本库的 URL 改变了),然后你的外部定义并不会改变,它可能就失效了。

要避免这样的问题,Subversion 客户端程序 1.5 版及更高版本支持相对外部 URL。四种不同的指定相对 URL 的方式被支持。在下面的例子中,假设我们有两个版本库: 一个位于 http://example.com/svn/repos-1,另一个位于 http://example.com/svn/repos-2。我们签出 http://example.com/svn/repos-1/project/trunkC:\Working 并且在 trunk 设置 svn:externals 属性。

相对于父目录

These URLs always begin with the string ../ for example:

../../widgets/foo  common/foo-widget
            

This will extract http://example.com/svn/repos-1/widgets/foo into C:\Working\common\foo-widget.

注意: URL 是相对于具有 svn:externals 属性的目录所对应的 URL,而不是外部条目将要写入的硬盘目录。

相对于版本库的根

These URLs always begin with the string ^/ for example:

^/widgets/foo  common/foo-widget
            

This will extract http://example.com/svn/repos-1/widgets/foo into C:\Working\common\foo-widget.

You can easily refer to other repositories with the same SVNParentPath (a common directory holding several repositories). For example:

^/../repos-2/hammers/claw  common/claw-hammer
            

This will extract http://example.com/svn/repos-2/hammers/claw into C:\Working\common\claw-hammer.

相对于方案

URLs beginning with the string // copy only the scheme part of the URL. This is useful when the same hostname must the accessed with different schemes depending upon network location; e.g. clients in the intranet use http:// while external clients use svn+ssh://. For example:

//example.com/svn/repos-1/widgets/foo  common/foo-widget
            

This will extract http://example.com/svn/repos-1/widgets/foo or svn+ssh://example.com/svn/repos-1/widgets/foo depending on which method was used to checkout C:\Working.

相对于服务器主机名称

URLs beginning with the string / copy the scheme and the hostname part of the URL, for example:

/svn/repos-1/widgets/foo  common/foo-widget
            

This will extract http://example.com/svn/repos-1/widgets/foo into C:\Working\common\foo-widget. But if you checkout your working copy from another server at svn+ssh://another.mirror.net/svn/repos-1/project1/trunk then the external reference will extract svn+ssh://another.mirror.net/svn/repos-1/widgets/foo.

You can also specify a peg and operative revision for the URL if required. To learn more about peg and operative revisions, please read the corresponding chapter in the Subversion book.

重要

If you specify the target folder for the external as a subfolder like in the examples above, make sure that all folders in between are versioned as well. So for the examples above, the folder common should be versioned!

While the external will work in most situations properly if folders in between are not versioned, there are some operations that won't work as you expect. And the status overlay icons in explorer will also not show the correct status.

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

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

外部文件

从 Subversion 1.6 版起,你可以将单独的文件作为外部引用添加到你的工作副本中,它使用和外部文件夹相同的语法格式。然而,这里有一些限制。

  • The path to the file external must be a direct child of the folder where you set the svn:externals property.

  • 外部文件的 URL 必须和插入外部文件的 URL 位于同一个版本库;不同版本库之间的外部文件不被支持。

外部文件行为在许多方面与其它版本控制的文件类似,但是它们不能使用普通的命令进行移动或删除;必须通过修改 svn:externals 来替代上述操作。

Creating externals via drag and drop

If you already have a working copy of the files or folders you want to include as externals in another working copy, you can simply add those via drag and drop from the windows explorer.

Simply right drag the file or folder from one working copy to where you want those to be included as externals. A context menu appears when you release the mouse button: SVN Add as externals here if you click on that context menu entry, the svn:externals property is automatically added. All you have to do after that is commit the property changes and update to get those externals properly included in your working copy.