注册
登录
svn
如何在Subversion中忽略文件?
返回
如何在Subversion中忽略文件?
作者:
狗头军师
发布时间:
2025-02-22 03:59:51 (9天前)
如何在Subversion中忽略文件?
另外,如何查找不受版本控制的文件?
收藏
举报
2 条回复
1#
回复此人
v-star*위위
|
2020-08-18 15-38
此答案已更新,以匹配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(基于文件)- C:\Users\{you}\AppData\Roaming\Subversion\config 视窗(基于注册表) - Software\Tigris.org\Subversion\Config\Miscellany\global-ignores在这两个HKLM和HKCU。 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 ``` (因此./subdirectory/ignoreThis,即使ignoreThis.txt在.回购根目录上应用了“ ” ,也不会忽略该文件)。 因此,要递归应用忽略列表,必须使用svn propset svn:ignore
. --recursive。 这将在每个子目录上创建属性的副本。 如果
子目录中的值不同,则子目录的值将完全覆盖父目录,因此不会产生“累加”效果。 因此,如果您
在根目录上更改了.,则必须使用进行更改,--recursive以覆盖子目录和子目录中的目录。 我注意到命令行语法是违反直觉的。 我开始假设您将通过键入类似svn ignore pathToFileToIgnore.txt以下内容来忽略SVN中的文件,但这不是SVN的忽略功能的工作方式。 3- 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将隐藏被忽略的文件(即,与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! ```
编辑
登录
后才能参与评论