如何在Subversion中忽略文件?

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


当前回答

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

查看SVN属性中的ignore属性。

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

其他回答

另一个解决方案是:

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

或者一行一行

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"中的文件 删除文件

使用以下命令创建一个不在版本控制文件下的列表。

svn status | grep "^\?" | awk "{print \$2}" > ignoring.txt

然后编辑该文件,只留下您想要忽略的文件。然后使用这个来忽略文件中列出的文件:

svn propset svn:ignore -F ignoring.txt .

注意行尾的点。它告诉SVN正在当前目录上设置属性。

删除文件:

rm ignoring.txt

最后提交,

svn ci --message "ignoring some files"

然后你可以通过以下方法检查哪些文件被忽略:

svn proplist -v

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

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

似乎没有人提到过……

svn propedit 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

哈哈!