如何使用 SVN 忽略目录?
I just started using SVN, and I have a cache directory that I don't need under source control. How can I ignore the whole directory/folder with SVN?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(22)
如果您的项目目录名为 /Project,并且您的缓存目录名为 /Project/Cache,那么您需要在 /Project 上设置 subversion 属性。 属性名称应为“svn:ignore”,属性值应为“Cache”。
有关属性的更多信息,请参阅 Subversion 手册中的此页面。
If your project directory is named /Project, and your cache directory is named /Project/Cache, then you need to set a subversion property on /Project. The property name should be "svn:ignore" and the property value should be "Cache".
Refer to this page in the Subversion manual for more on properties.
杰森的回答就能解决问题。 但是,不要将 svn:ignore 设置为“.”。 在缓存目录上,您可能希望在父目录的 svn:ignore 属性中包含“cache”,以防缓存目录并不总是存在。 我在许多“一次性”文件夹上执行此操作。
Jason's answer will do the trick. However, instead of setting svn:ignore to "." on the cache directory, you may want to include "cache" in the parent directory's svn:ignore property, in case the cache directory is not always present. I do this on a number of "throwaway" folders.
我在忽略嵌套目录时遇到问题; 我想忽略的顶级目录不会显示“svn status”,但所有子目录都会显示。 这对其他人来说可能是不言而喻的,但我想我应该分享一下:
示例:
I had problems getting nested directories to be ignored; the top directory I wanted to ignore wouldn't show with 'svn status' but all the subdirs did. This is probably self-evident to everyone else, but I thought I'd share it:
EXAMPLE:
“谢谢” svn 提供了如此可怕、虚假且困难的忽略文件的方法。
所以我写了一个脚本 svn-ignore-all:
另外,忽略特定列表文件/路径名,我们可以使用这个变体 svn-ignore。 我想 svn-ignore-all 应该像 xargs svn-ignore 一样。
另一件事:我倾向于用许多随机文件污染我的 svn 签出。 当需要提交时,我将这些文件移动到“旧”子目录中,并告诉 svn 忽略“旧”。
"Thank-you" svn for such a hideous, bogus and difficult way to ignore files.
So I wrote a script svn-ignore-all:
Also, to ignore specific list of files / pathnames, we can use this variant svn-ignore. I guess svn-ignore-all should really be like xargs svn-ignore.
One more thing: I tend to pollute my svn checkouts with many random files. When it's time to commit, I move those files into an 'old' subdirectory, and tell svn to ignore 'old'.
如果您使用 TortoiseSVN 之类的 SVN 前端或某种 IDE 集成,则与提交/添加操作相同的菜单中还应该有一个忽略选项。
If you are using a frontend for SVN like TortoiseSVN, or some sort of IDE integration, there should also be an ignore option in the same menu are as the commit/add operation.
保留 SVN 将忽略的目录:
TO KEEP DIRECTORIES THAT SVN WILL IGNORE:
设置 svn:ignore 属性。 大多数 UI svn 工具都有一种方法可以做到这一点以及链接中的命令行讨论。
Set the svn:ignore property. Most UI svn tools have a way to do this as well as the command line discussion in the link.
由于您使用的是版本,因此实际上非常简单:
Since you're using Versions it's actually really easy:
也要注意你的尾随斜杠。 我发现在我的忽略设置文件中包含
images/*
并没有忽略./images/
。 当我运行 svn status -u 时,它仍然显示? 图片
。 因此,我只是将忽略设置更改为仅图像
,没有斜杠。 进行了状态检查并将其清除。Watch your trailing slashes too. I found that including
images/*
in my ignore setting file did not ignore./images/
. When I ransvn status -u
it still showed? images
. So, I just changed the ignore setting to justimages
, no slashes. Ran a status check and that cleared it out.在花了很多时间寻找如何完成这个简单的活动之后,我决定发布它并不难找到一个像样的解释。
首先让示例结构
$ svn st
? 项目/主干/目标
? project/trunk/myfile.x
1 – 首先配置编辑器,在 mycase vim 中
export SVN_EDITOR=vim
2 – “svn propedit svn:ignore project/trunk/” 将打开一个新文件,您可以在我们的情况下添加文件和子目录,输入“target”保存并关闭文件并运行
$ svn st
? 项目/trunk/myfile.x
谢谢。
After losing a lot of time looking for how to do this simple activity, I decided to post it was not hard to find a decent explanation.
First let the sample structure
$ svn st
? project/trunk/target
? project/trunk/myfile.x
1 – first configure the editor,in mycase vim
export SVN_EDITOR=vim
2 – “svn propedit svn:ignore project/trunk/” will open a new file and you can add your files and subdirectory in us case type “target” save and close file and works
$ svn st
? project/trunk/myfile.x
thanks.
下面是一个目录结构示例:
在
project
中,您会看到缓存目录未添加并按原样显示。要设置忽略属性,请执行以下操作
其中,
svn:ignore
是您要设置的属性的名称,cache
是该属性的值,.
是您设置的目录。正在设置此属性。 它应该是需要该属性的cache
目录的父目录。检查设置了哪些属性:
查看 svn:ignore 的值:
删除先前设置的属性:
Here's an example directory structure:
When in
project
you see that your cache directory is not added and shows up as such.To set the ignore property, do
where
svn:ignore
is the name of the property you're setting,cache
is the value of the property, and.
is the directory you're setting this property on. It should be the parent directory of thecache
directory that needs the property.To check what properties are set:
To see the value of
svn:ignore
:To delete properties previously set:
设置父目录的 svn:ignore 属性:
如果您有多个要忽略的内容,请在属性值中用换行符分隔。 在这种情况下,使用外部编辑器编辑属性值会更容易:
Set the
svn:ignore
property of the parent directory:If you have multiple things to ignore, separate by newlines in the property value. In that case it's easier to edit the property value using an external editor:
需要注意的是:
在命令行上你不能使用
这也会添加被忽略的文件,因为命令行扩展了
*
,因此svn add
认为你想要所有文件待补充。 因此用这个代替:Important to mention:
On the commandline you can't use
This will also add the ignored files, because the command line expands
*
and thereforesvn add
believes that you want all files to be added. Therefore use this instead:由于我花了一段时间尝试让它工作,应该注意的是,如果文件已存在于 SVN 中,则需要
svn delete
它们,然后编辑svn:ignore< /代码> 属性。
我知道这似乎很明显,但当我认为它会在本地忽略它们时,它们一直在我的
svn status
列表中显示为?
。Since I spent a while trying to get this to work, it should be noted that if the files already exist in SVN, you need to
svn delete
them, and then edit thesvn:ignore
property.I know that seems obvious, but they kept showing up as
?
in mysvn status
list, when I thought it would just ignore them locally.稍微扩展一下,如果您使用 svn 命令行工具执行此操作,您需要输入:
这将打开您选择的文本编辑器,然后输入 '*' 忽略其中的所有内容,然后保存+退出 - 这将在 svn 中包含目录本身,但忽略其中的所有文件,要忽略目录,请使用父目录的路径,然后在文件中键入目录的名称。 保存后,运行更新('svn up'),然后签入适当的路径。
To expand slightly, if you're doing this with the svn command-line tool, you want to type:
which will open your text-editor of choice, then type '*' to ignore everything inside it, and save+quit - this will include the directory itself in svn, but ignore all the files inside it, to ignore the directory, use the path of the parent, and then type the name of the directory in the file. After saving, run an update ('svn up'), and then check in the appropriate path.
在父目录上设置 svn:ignore 属性:
这将覆盖 svn:ignore 的任何当前值。 您可以使用以下命令编辑值:
这将打开您的编辑器。 您可以添加多个模式,每行一个。
您可以通过以下方式查看当前值:
如果您使用的是 GUI,则应该有一个菜单选项可以执行此操作。
Set the
svn:ignore
property on the parent directory:This will overwrite any current value of
svn:ignore
. You an edit the value with:Which will open your editor. You can add multiple patterns, one per line.
You can view the current value with:
If you are using a GUI there should be a menu option to do this.
忽略多个条目的命令有点棘手并且需要反斜杠。
此命令将忽略当前目录中名为
cache
、tmp
、null
和and_so_on
的任何内容。The command to ignore multiple entries is a little tricky and requires backslashes.
This command will ignore anything named
cache
,tmp
,null
, andand_so_on
in the current directory.Bash oneliner 用于多个忽略:
Bash oneliner for multiple ignores:
如果您使用特定的 SVN 客户端 TortoiseSVN,那么在提交时,您可以选择右键单击项目并选择“添加到忽略列表”。
If you are using the particular SVN client TortoiseSVN, then on commit, you have the option of right clicking items and selecting "Add to ignore list".
...如果您想忽略多个目录(例如
build/
temp/
和*.tmp
文件),您可以分两步完成(忽略第一步并编辑忽略属性(请参阅此处的其他答案),或者可以在命令行上编写类似的内容。
...and if you want to ignore more than one directory (say
build/
temp/
and*.tmp
files), you could either do it in two steps (ignoring the first and edit ignore properties (see other answers here) or one could write something likeon the command line.
首先删除它...
如果您的目录 foo 已经处于版本控制之下,请先使用以下命令删除它:
...然后忽略:
Remove it first...
If your directory
foo
is already under version control, remove it first with:...then ignore:
感谢以上所有的贡献。 我只想分享一些我在忽略文件时的经验中的附加信息。
当文件夹已经受到修订控制时
在svn import和svn co文件之后,我们通常第一次做的事情。
所有运行时缓存、附件文件夹都将受到版本控制。
因此,在svn ps svn:ignore之前,我们需要将其从存储库中删除。
对于以上版本的 SVN 1.5,我们可以使用 svn del --keep-local your_folder,
但对于早期版本,我的解决方案是:
.svn
隐藏文件夹)当我们需要忽略多个文件夹
svn:ignore
svn pe
将需要编辑文本文件,如果需要使用 vi:该文件看起来就像这样:
Thanks for all the contributions above. I would just like to share some additional information from my experiences while ignoring files.
When the folders are already under revision control
After svn import and svn co the files, what we usually do for the first time.
All runtime cache, attachments folders will be under version control.
so, before svn ps svn:ignore, we need to delete it from the repository.
With SVN version 1.5 above we can use
svn del --keep-local your_folder
,but for an earlier version, my solution is:
.svn
hidden folder)When we need more than one folder to be ignored
svn:ignore
svn pe
will need to edit the text file, and you can use this command if required to set your text editor using vi:The file looks something simply like this: