如何在Subversion中忽略文件?

另外,我如何找到不在版本控制下的文件?


当前回答

打开你使用JetBrains产品(即Pycharm) 然后点击顶部工具栏上的“提交”按钮或使用快捷键“ctrl + k” screenshot_toolbar 在提交界面上,将不需要的文件移动到另一个更改列表,如下所示。 screenshot_commit_change 下次您只能提交默认更改列表。

其他回答

在TortoiseSVN中很容易管理SVN忽略。打开TortoiseSVN,右键单击文件菜单,然后选择添加到忽略列表。

这将在svn:ignore属性中添加文件。 当我们检入文件时,那些与svn:ignore匹配的文件将被忽略并且不会提交。

在Visual Studio项目中,我们添加了以下文件来忽略:

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

我们在Comparetrap的SVN上成功地使用了该方法管理源代码

在你的工作副本上使用命令svn status来显示文件的状态,那些尚未处于版本控制(并且没有被忽略)的文件旁边会有一个问号。

至于忽略需要编辑svn:ignore属性的文件,请阅读svnbook中http://svnbook.red-bean.com/en/1.5/svn.advanced.props.special.ignore.html的“忽略Unversioned Items”章节。本书还详细介绍了svn status的使用方法。

svn status将告诉您哪些文件不在svn中,以及哪些文件发生了更改。

查看SVN属性中的ignore属性。

对于SVN的所有内容,红皮书都是必读的。

.gitignore式的方法

您可以忽略像.gitignore这样的文件或目录。只需创建一个你想忽略的目录/文件列表的文本文件,并运行下面的代码:

svn propset svn:ignore -F ignorelist.txt .

或者如果你不想使用文本文件,你可以这样做:

svn propset svn:ignore "first
 second
 third" .

来源:Karsten's Blog -从命令行设置svn:ignore多个文件

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

你有两个问题:

将文件标记为忽略:

所谓“被忽略的文件”,我的意思是该文件即使是“未版本化的”也不会出现在列表中:您的SVN客户端会假装该文件在文件系统中根本不存在。

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

从1.8版(2013年6月)开始,Subversion支持3种不同的指定文件模式的方式。下面是一个有例子的总结:

1 -运行时配置区域-全局忽略选项:

这是一个客户端设置,所以你的全局忽略列表不会被其他用户共享,它适用于你签入到你的计算机上的所有回购。 此设置在运行时配置区域文件中定义: Windows(基于文件的)- C:\Users\{you}\AppData\Roaming\Subversion\config Windows(基于注册表)- Software\Tigris.org\Subversion\Config\Miscellany\global-忽略HKLM和HKCU。 Linux/Unix - ~/.subversion/config

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

This is stored within the repo, so other users will have the same ignore files. Similar to how .gitignore works. svn:ignore is applied to directories and is non-recursive or inherited. Any file or immediate subdirectory of the parent directory that matches the File Pattern will be excluded. While SVN 1.8 adds the concept of "inherited properties", the svn:ignore property itself is ignored in non-immediate descendant directories: 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 (So the file ./subdirectory/ignoreThis is not ignored, even though "ignoreThis.txt" is applied on the . repo root). Therefore, to apply an ignore list recursively you must use svn propset svn:ignore <filePattern> . --recursive. This will create a copy of the property on every subdirectory. If the <filePattern> value is different in a child directory then the child's value completely overrides the parents, so there is no "additive" effect. So if you change the <filePattern> on the root ., then you must change it with --recursive to overwrite it on the child and descendant directories. I note that the command-line syntax is counter-intuitive. I started-off assuming that you would ignore a file in SVN by typing something like svn ignore pathToFileToIgnore.txt however this is not how SVN's ignore feature works.

3—svn:global-忽略属性。要求SVN 1.8(2013年6月):

This is similar to svn:ignore, except it makes use of SVN 1.8's "inherited properties" feature. Compare to svn:ignore, the file pattern is automatically applied in every descendant directory (not just immediate children). This means that is unnecessary to set svn:global-ignores with the --recursive flag, as inherited ignore file patterns are automatically applied as they're inherited. Running the same set of commands as in the previous example, but using svn:global-ignores instead: 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用户:

This whole arrangement was confusing for me, because TortoiseSVN's terminology (as used in their Windows Explorer menu system) was initially misleading to me - I was unsure what the significance of the Ignore menu's "Add recursively", "Add *" and "Add " options. I hope this post explains how the Ignore feature ties-in to the SVN Properties feature. That said, I suggest using the command-line to set ignored files so you get a feel for how it works instead of using the GUI, and only using the GUI to manipulate properties after you're comfortable with the command-line.

列出被忽略的文件:

命令svn status将隐藏被忽略的文件(即匹配RGA全局忽略模式的文件,或匹配直接父目录的svn:忽略模式的文件,或匹配任何父目录的svn:全局忽略模式的文件)。

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

哈哈!