(此答案已更新以匹配 SVN 1.8 和 1.9 的行为)
您有 2 个问题:
将文件标记为忽略:
我所说的“忽略文件”是指该文件不会出现在列表中,即使是“未版本控制”:您的 SVN 客户端会假装该文件在文件系统中根本不存在。
忽略的文件由“文件模式”指定。文件模式的语法和格式在 SVN 的在线文档中进行了解释:http://svnbook.red-bean.com/nightly/en/svn.advanced.props.special.ignore.html http://svnbook.red-bean.com/nightly/en/svn.advanced.props.special.ignore.html“Subversion 中的文件模式”。
Subversion 从 1.8 版(2013 年 6 月)及更高版本开始,支持 3 种不同的指定文件模式的方式。以下是带有示例的摘要:
1 - 运行时配置区域 -global-ignores
option:
- 这是一个仅客户端设置,所以你的
global-ignores
列表不会被其他用户共享,并且它适用于您在计算机上签出的所有存储库。
- This setting is defined in your Runtime Configuration Area file:
- Windows(基于文件)-
C:\Users\{you}\AppData\Roaming\Subversion\config
- Windows(基于注册表)-
Software\Tigris.org\Subversion\Config\Miscellany\global-ignores
同时HKLM
and HKCU
.
- Linux/Unix -
~/.subversion/config
2 - The svn:ignore
属性,在目录(而不是文件)上设置:
-
这存储在存储库中,因此其他用户将拥有相同的忽略文件。类似于如何.gitignore
works.
-
svn:ignore
应用于目录并且是非递归或继承的。任何文件或即时与文件模式匹配的父目录的子目录将被排除。
-
虽然SVN 1.8增加了“继承属性”的概念,svn:ignore
在非直接后代目录中属性本身被忽略:
cd ~/myRepoRoot # Open an existing repo.
echo "foo" > "ignoreThis.txt" # Create a file called "ignoreThis.txt".
svn status # Check to see if the file is ignored or not.
> ? ./ignoreThis.txt
> 1 unversioned file # ...it is NOT currently ignored.
svn propset svn:ignore "ignoreThis.txt" . # Apply the svn:ignore property to the "myRepoRoot" directory.
svn status
> 0 unversioned files # ...but now the file is ignored!
cd subdirectory # now open a subdirectory.
echo "foo" > "ignoreThis.txt" # create another file named "ignoreThis.txt".
svn status
> ? ./subdirectory/ignoreThis.txt # ...and is is NOT ignored!
> 1 unversioned file
(所以文件./subdirectory/ignoreThis
并没有被忽视,尽管“ignoreThis.txt
” 应用于.
回购根)。
-
因此,要递归地应用忽略列表,您必须使用svn propset svn:ignore <filePattern> . --recursive
.
- 这将在每个子目录上创建该属性的副本。
- If the
<filePattern>
子目录中的值不同,则子目录的值完全覆盖父目录,因此不存在“相加”效果。
- 所以如果你改变
<filePattern>
在根上.
,那么你必须将其更改为--recursive
在子目录和后代目录上覆盖它。
-
我注意到命令行语法是违反直觉的。
- 我一开始假设你会通过输入类似的内容来忽略 SVN 中的文件
svn ignore pathToFileToIgnore.txt
然而这并不是 SVN 忽略功能的工作原理。
3- The svn:global-ignores
财产。需要 SVN 1.8(2013 年 6 月):
-
这类似于svn:ignore
,只不过它利用了 SVN 1.8 的“继承属性”功能。
-
相比于svn:ignore
,文件模式会自动应用于每个后代目录(不仅仅是直接子目录)。
- 这意味着不需要设置
svn:global-ignores
与--recursive
标志,因为继承的忽略文件模式在继承时会自动应用。
-
运行与上一个示例相同的命令集,但使用svn:global-ignores
反而:
cd ~/myRepoRoot # Open an existing repo
echo "foo" > "ignoreThis.txt" # Create a file called "ignoreThis.txt"
svn status # Check to see if the file is ignored or not
> ? ./ignoreThis.txt
> 1 unversioned file # ...it is NOT currently ignored
svn propset svn:global-ignores "ignoreThis.txt" .
svn status
> 0 unversioned files # ...but now the file is ignored!
cd subdirectory # now open a subdirectory
echo "foo" > "ignoreThis.txt" # create another file named "ignoreThis.txt"
svn status
> 0 unversioned files # the file is ignored here too!
对于 TortoiseSVN 用户:
整个安排让我感到困惑,因为 TortoiseSVN 的术语(在他们的 Windows 资源管理器菜单系统中使用)最初误导了我 - 我不确定忽略菜单的“递归添加”、“添加 *”和“添加”的意义是什么选项。我希望这篇文章能够解释“忽略”功能如何与 SVN 属性功能相关联。也就是说,我建议使用命令行来设置忽略的文件,以便您了解它的工作原理,而不是使用 GUI,并且仅在您熟悉命令行后才使用 GUI 来操作属性。
列出被忽略的文件:
命令svn status
将隐藏被忽略的文件(即与 RCA 匹配的文件)global-ignores
模式,或匹配直接父目录的svn:ignore
模式或匹配任何祖先目录svn:global-ignores
图案。
Use the --no-ignore
选项来查看列出的这些文件。被忽略的文件的状态为I
,然后将输出通过管道传输到grep
仅显示以“I”开头的行。
命令是:
svn status --no-ignore | grep "^I"
例如:
svn status
> ? foo # An unversioned file
> M modifiedFile.txt # A versioned file that has been modified
svn status --no-ignore
> ? foo # An unversioned file
> I ignoreThis.txt # A file matching an svn:ignore pattern
> M modifiedFile.txt # A versioned file that has been modified
svn status --no-ignore | grep "^I"
> I ignoreThis.txt # A file matching an svn:ignore pattern
ta-da!