如何在Subversion中忽略文件?

时间:2020-03-05 18:59:35  来源:igfitidea点击:

如何在Subversion中忽略文件?

另外,如何查找不受版本控制的文件?

解决方案

回答

(此答案已更新,以匹配SVN 1.8和1.9的行为)

我们有2个问题:

所谓"被忽略的文件",是指该文件甚至不会以"未版本控制"的形式出现在列表中:SVN客户端会假装该文件在文件系统中根本不存在。

忽略的文件由"文件模式"指定。 SVN的在线文档中说明了文件模式的语法和格式:http://svnbook.red-bean.com/nightly/en/svn.advanced.props.special.ignore.html" Subversion中的文件模式"。

从1.8版(2013年6月)及更高版本开始,Subversion支持3种不同的指定文件模式的方式。这是一个带有示例的摘要:

1-运行时配置区域-global-ignores选项:

  • 这是仅客户端设置,因此global-ignores列表不会被其他用户共享,并且适用于我们在计算机上签出的所有存储库。
  • Windows(基于注册表)-HKLM和HKCU中的Software \ Tigris.org \ Subversion \ Config \ Miscellany \ global-ignores`。
  • Linux / Unix-〜/ .subversion / config

2-svn:ignore属性,它在目录(不是文件)上设置:

  • 这存储在存储库中,因此其他用户将具有相同的忽略文件。类似于.gitignore的工作方式。
  • 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

(因此,即使将" .ignoreThis.txt"应用于"。"仓库根目录,也不会忽略文件" ./subdirectory/ignoreThis")。

  • 如果子目录中的<filePattern>值不同,则该子目录的值将完全覆盖父目录,因此不会产生"累加"效果。
  • 因此,如果我们在根.上更改了<filePattern>,则必须使用--recursive对其进行更改,以在子目录和后代目录中将其覆盖。

3-svn:global-ignores属性。需要SVN 1.8(2013年6月):

  • 这类似于svn:ignore,不同之处在于它利用了SVN 1.8的"继承的属性"功能。
  • 运行与上一个示例相同的命令集,但是使用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命令将隐藏被忽略的文件(即,与RGA的global-ignores模式匹配的文件,或者与直接父目录的svn:ignore模式匹配的文件,或者与任何祖先目录的svn:global-ignores匹配的文件。图案。

使用--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!

回答

" svn status"将告诉我们哪些文件不在SVN中,以及发生了什么更改。

查看SVN属性中的ignore属性。

对于SVN的所有内容,必须阅读《红皮书》。

回答

我们还可以在SVN的配置文件中设置全局忽略模式。

回答

在工作副本上使用命令svn status显示文件的状态,尚未受版本控制(并且未被忽略)的文件旁边将带有问号。

至于忽略文件,我们需要编辑svn:ignore属性,请阅读svnbook中的忽略未版本化项目一章,网址为http://svnbook.red-bean.com/en/1.5/svn.advanced.props.special.ignore。 html。该书还介绍了有关使用svn状态的更多信息。

回答

如果我们使用的是TortoiseSVN,请右键单击文件,然后选择TortoiseSVN /添加到忽略列表。这会将文件/通配符添加到svn:ignore属性。

当我们检入文件时,将检查svn:ignore,而匹配的文件将被忽略。对于Visual Studio .NET项目,我具有以下忽略列表:

bin obj
*.exe
*.dll
_ReSharper
*.pdb
*.suo

我们可以在TortoiseSVN /属性的上下文菜单中找到此列表。