如何在Subversion中忽略文件?

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


当前回答

bkbilly回答的一个更可读的版本:

svn st | awk '/^?/{print $2}' > svnignore.txt
svn propget svn:ignore >> svnignore.txt
svn propset svn:ignore -F svnignore.txt .
rm svnignore.txt

它的作用:

从svn中获取状态文件 保存所有文件?到svnignore.txt文件 获取已经被忽略的文件,并将它们追加到“svnignore.txt”文件中。 告诉svn忽略"svnignore.txt"中的文件 删除文件

其他回答

当使用propedit时,请确保没有任何尾随空格,因为这会导致文件被排除在忽略列表之外。

如果你在linux上使用tab-autocomplete来创建文件,这些会自动插入:

svn propset svn:ignore 'file1
file2' .

(这个答案已经更新,以匹配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

哈哈!

此外,如果你使用Tortoise SVN,你可以这样做:

在上下文菜单中选择“TortoiseSVN”,然后选择“属性” 在出现的窗口中点击“新建”,然后点击“高级” 在“属性名称”对面出现的窗口中选择或输入“svn:ignore”,在“属性值”对面输入所需的文件名或文件夹名或文件掩码(在我的例子中是“*/target”),点击“递归应用属性” 好的。好的。 提交

.gitignore式的方法

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

svn propset svn:ignore -F ignorelist.txt .

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

svn propset svn:ignore "first
 second
 third" .

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

我找到了这篇文章。svnignore Java示例。

例如:Ruby on Rails的.svnignore,

/log

/public/*.JPEG
/public/*.jpeg
/public/*.png
/public/*.gif

*.*~

在那之后:

svn propset svn:ignore -F .svnignore .

关于.gitignore的例子。你可以使用你的.svnignore

https://github.com/github/gitignore