如何使用 SVN 忽略目录?

发布于 2024-07-05 10:47:59 字数 318 浏览 10 评论 0原文

我刚刚开始使用 SVN,并且我有一个在源代码管理下不需要的缓存目录。 如何使用 SVN 忽略整个目录/文件夹?

我正在使用 版本TextMate

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?

I am using Versions and TextMate on OS X and commandline.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(22

两仪 2024-07-12 10:48:00

如果您的项目目录名为 /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.

北城挽邺 2024-07-12 10:48:00

杰森的回答就能解决问题。 但是,不要将 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.

半葬歌 2024-07-12 10:48:00

我在忽略嵌套目录时遇到问题; 我想忽略的顶级目录不会显示“svn status”,但所有子目录都会显示。 这对其他人来说可能是不言而喻的,但我想我应该分享一下:

示例:

/后备箱

/主干/缓存

/trunk/cache/subdir1

/trunk/cache/subdir2

cd /trunk
svn ps svn:ignore . /cache
cd /trunk/cache
svn ps svn:ignore . *
svn ci

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:

/trunk

/trunk/cache

/trunk/cache/subdir1

/trunk/cache/subdir2

cd /trunk
svn ps svn:ignore . /cache
cd /trunk/cache
svn ps svn:ignore . *
svn ci
鹿童谣 2024-07-12 10:48:00

“谢谢” svn 提供了如此可怕、虚假且困难的忽略文件的方法。

所以我写了一个脚本 svn-ignore-all

#!/bin/sh

# svn-ignore-all

# usage: 
#   1. run svn status to see what is going on at each step 
#   2. add or commit all files that you DO want to have in svn
#   3. remove any random files that you don't want to svn:ignore
#   4. run this script to svn:ignore everything marked '?' in output of `svn status`

svn status |
grep '^?' |
sed 's/^? *//' |
while read f; do
    d=`dirname "$f"`
    b=`basename "$f"`
    ignore=`svn propget svn:ignore "$d"`
    if [ -n "$ignore" ]; then
        ignore="$ignore
"
    fi
    ignore="$ignore$b"
    svn propset svn:ignore "$ignore" "$d"
done

另外,忽略特定列表文件/路径名,我们可以使用这个变体 svn-ignore。 我想 svn-ignore-all 应该像 xargs svn-ignore 一样。

#!/bin/sh

# svn-ignore

# usage:
#   svn-ignore file/to/ignore ...

for f; do
    d=`dirname "$f"`
    b=`basename "$f"`
    ignore=`svn propget svn:ignore "$d"`
    if [ -n "$ignore" ]; then
        ignore="$ignore
"
    fi
    ignore="$ignore$b"
    svn propset svn:ignore "$ignore" "$d"
done

另一件事:我倾向于用许多随机文件污染我的 svn 签出。 当需要提交时,我将这些文件移动到“旧”子目录中,并告诉 svn 忽略“旧”。

"Thank-you" svn for such a hideous, bogus and difficult way to ignore files.

So I wrote a script svn-ignore-all:

#!/bin/sh

# svn-ignore-all

# usage: 
#   1. run svn status to see what is going on at each step 
#   2. add or commit all files that you DO want to have in svn
#   3. remove any random files that you don't want to svn:ignore
#   4. run this script to svn:ignore everything marked '?' in output of `svn status`

svn status |
grep '^?' |
sed 's/^? *//' |
while read f; do
    d=`dirname "$f"`
    b=`basename "$f"`
    ignore=`svn propget svn:ignore "$d"`
    if [ -n "$ignore" ]; then
        ignore="$ignore
"
    fi
    ignore="$ignore$b"
    svn propset svn:ignore "$ignore" "$d"
done

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.

#!/bin/sh

# svn-ignore

# usage:
#   svn-ignore file/to/ignore ...

for f; do
    d=`dirname "$f"`
    b=`basename "$f"`
    ignore=`svn propget svn:ignore "$d"`
    if [ -n "$ignore" ]; then
        ignore="$ignore
"
    fi
    ignore="$ignore$b"
    svn propset svn:ignore "$ignore" "$d"
done

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'.

独享拥抱 2024-07-12 10:48:00

如果您使用 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.

刘备忘录 2024-07-12 10:48:00

保留 SVN 将忽略的目录:

  1. 这将从存储库中删除文件,但将该目录保留在 SVN 控制之下:

svn delete --keep-local 路径/directory_to_keep/*

  1. 然后设置为忽略目录(和所有内容):

svn propset svn:ignore "*" path/directory_to_keep

TO KEEP DIRECTORIES THAT SVN WILL IGNORE:

  1. this will delete the files from the repository, but keep the directory under SVN control:

svn delete --keep-local path/directory_to_keep/*

  1. then set to ignore the directory (and all content):

svn propset svn:ignore "*" path/directory_to_keep

冷情 2024-07-12 10:48:00

设置 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.

遇到 2024-07-12 10:48:00

由于您使用的是版本,因此实际上非常简单:

  • 浏览已签出的副本 单击
  • 要忽略的目录
  • 在右侧的“忽略”框中,单击“编辑
  • 类型 *.*”以忽略所有文件(或 *.jpg 仅用于 jpg 文件, ETC。)

Since you're using Versions it's actually really easy:

  • Browse your checked-out copy
  • Click the directory to ignore
  • In the "Ignore box on the right click Edit
  • Type *.* to ignore all files (or *.jpg for just jpg files, etc.)
债姬 2024-07-12 10:48:00

也要注意你的尾随斜杠。 我发现在我的忽略设置文件中包含 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 ran svn status -u it still showed ? images. So, I just changed the ignore setting to just images, no slashes. Ran a status check and that cleared it out.

三月梨花 2024-07-12 10:48:00

在花了很多时间寻找如何完成这个简单的活动之后,我决定发布它并不难找到一个像样的解释。

首先让示例结构

$ 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.

失而复得 2024-07-12 10:47:59

下面是一个目录结构示例:

\project
    \source
    \cache
    \other

project 中,您会看到缓存目录未添加并按原样显示。

> svn status
M  source
?  cache

要设置忽略属性,请执行以下操作

svn propset svn:忽略缓存。

其中,svn:ignore 是您要设置的属性的名称,cache 是该属性的值,. 是您设置的目录。正在设置此属性。 它应该是需要该属性的 cache 目录的父目录。

检查设置了哪些属性:

> svn proplist
Properties on '.':
  svn:ignore

查看 svn:ignore 的值:

> svn propget svn:ignore
cache

删除先前设置的属性:

svn propdel svn:ignore

Here's an example directory structure:

\project
    \source
    \cache
    \other

When in project you see that your cache directory is not added and shows up as such.

> svn status
M  source
?  cache

To set the ignore property, do

svn propset svn:ignore cache .

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 the cache directory that needs the property.

To check what properties are set:

> svn proplist
Properties on '.':
  svn:ignore

To see the value of svn:ignore:

> svn propget svn:ignore
cache

To delete properties previously set:

svn propdel svn:ignore
〃安静 2024-07-12 10:47:59

设置父目录的 svn:ignore 属性:

svn propset svn:ignore dirname .

如果您有多个要忽略的内容,请在属性值中用换行符分隔。 在这种情况下,使用外部编辑器编辑属性值会更容易:

svn propedit svn:ignore .

Set the svn:ignore property of the parent directory:

svn propset svn:ignore dirname .

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 propedit svn:ignore .
独自唱情﹋歌 2024-07-12 10:47:59

需要注意的是:

在命令行上你不能使用

svn add *

这也会添加被忽略的文件,因为命令行扩展了*,因此svn add认为你想要所有文件待补充。 因此用这个代替:

svn add --force .

Important to mention:

On the commandline you can't use

svn add *

This will also add the ignored files, because the command line expands * and therefore svn add believes that you want all files to be added. Therefore use this instead:

svn add --force .
复古式 2024-07-12 10:47:59

由于我花了一段时间尝试让它工作,应该注意的是,如果文件已存在于 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 the svn:ignore property.

I know that seems obvious, but they kept showing up as ? in my svn status list, when I thought it would just ignore them locally.

眼波传意 2024-07-12 10:47:59

稍微扩展一下,如果您使用 svn 命令行工具执行此操作,您需要输入:

svn propedit svn:ignore path/to/dir

这将打开您选择的文本编辑器,然后输入 '*' 忽略其中的所有内容,然后保存+退出 - 这将在 svn 中包含目录本身,但忽略其中的所有文件,要忽略目录,请使用父目录的路径,然后在文件中键入目录的名称。 保存后,运行更新('svn up'),然后签入适当的路径。

To expand slightly, if you're doing this with the svn command-line tool, you want to type:

svn propedit svn:ignore path/to/dir

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.

于我来说 2024-07-12 10:47:59

在父目录上设置 svn:ignore 属性:

$ cd parentdir
$ svn ps svn:ignore . 'cachedir'

这将覆盖 svn:ignore 的任何当前值。 您可以使用以下命令编辑值:

$ svn pe svn:ignore .

这将打开您的编辑器。 您可以添加多个模式,每行一个。

您可以通过以下方式查看当前值:

$ svn pg svn:ignore .

如果您使用的是 GUI,则应该有一个菜单选项可以执行此操作。

Set the svn:ignore property on the parent directory:

$ cd parentdir
$ svn ps svn:ignore . 'cachedir'

This will overwrite any current value of svn:ignore. You an edit the value with:

$ svn pe svn:ignore .

Which will open your editor. You can add multiple patterns, one per line.

You can view the current value with:

$ svn pg svn:ignore .

If you are using a GUI there should be a menu option to do this.

ぃ双果 2024-07-12 10:47:59

忽略多个条目的命令有点棘手并且需要反斜杠。

svn propset svn:ignore "cache\
tmp\
null\
and_so_on" .

此命令将忽略当前目录中名为 cachetmpnulland_so_on 的任何内容。

The command to ignore multiple entries is a little tricky and requires backslashes.

svn propset svn:ignore "cache\
tmp\
null\
and_so_on" .

This command will ignore anything named cache, tmp, null, and and_so_on in the current directory.

青芜 2024-07-12 10:47:59

Bash oneliner 用于多个忽略:

svn propset svn:ignore ".project"
\n'".settings"
\n'".buildpath" "yourpath"

Bash oneliner for multiple ignores:

svn propset svn:ignore ".project"
\n'".settings"
\n'".buildpath" "yourpath"
放手` 2024-07-12 10:47:59

如果您使用特定的 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".

迷路的信 2024-07-12 10:47:59

...如果您想忽略多个目录(例如 build/ temp/*.tmp 文件),您可以分两步完成(忽略第一步并编辑忽略属性(请参阅此处的其他答案),或者可以

svn propset svn:ignore "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 like

svn propset svn:ignore "build
temp
*.tmp" .

on the command line.

背叛残局 2024-07-12 10:47:59

首先删除它...

如果您的目录 foo 已经处于版本控制之下,请先使用以下命令删除它:

svn rm --keep-local foo

...然后忽略:

svn propset svn:ignore foo .

Remove it first...

If your directory foo is already under version control, remove it first with:

svn rm --keep-local foo

...then ignore:

svn propset svn:ignore foo .
简单爱 2024-07-12 10:47:59

感谢以上所有的贡献。 我只想分享一些我在忽略文件时的经验中的附加信息。


当文件夹已经受到修订控制时

svn importsvn co文件之后,我们通常第一次做的事情。

所有运行时缓存、附件文件夹都将受到版本控制。
因此,在svn ps svn:ignore之前,我们需要将其从存储库中删除。

对于以上版本的 SVN 1.5,我们可以使用 svn del --keep-local your_folder,
但对于早期版本,我的解决方案是:

  1. svn export文件夹的干净副本(没有.svn隐藏文件夹)
  2. svn del本地和存储库,
  3. svn ci
  4. 复制回文件夹
  5. svn st 并确认文件夹已标记为“?”
  6. 现在我们可以根据解决方案进行svn ps

当我们需要忽略多个文件夹

  • 在一个目录中我有两个文件夹需要设置为svn:ignore
  • 如果我们设置其中一个,另一个将被删除。
  • 然后我们想知道我们需要 svn pe

svn pe 将需要编辑文本文件,如果需要使用 vi

export SVN_EDITOR=vi
  1. 使用“o”,您可以打开一个新行
  2. 输入您想要忽略的所有文件夹名称
  3. 点击“esc”退出编辑模式的键
  4. 输入“:wq”,然后按 Enter 保存并退出

该文件看起来就像这样:

runtime
cache
attachments
assets

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:

  1. svn export a clean copy of your folders (without .svn hidden folder)
  2. svn del the local and repository,
  3. svn ci
  4. Copy back the folders
  5. Do svn st and confirm the folders are flagged as '?'
  6. Now we can do svn ps according to the solutions

When we need more than one folder to be ignored

  • In one directory I have two folders that need to be set as svn:ignore
  • If we set one, the other will be removed.
  • Then we wonder we need svn pe

svn pe will need to edit the text file, and you can use this command if required to set your text editor using vi:

export SVN_EDITOR=vi
  1. With "o" you can open a new line
  2. Type in all the folder names you want to ignore
  3. Hit 'esc' key to escape from edit mode
  4. Type ":wq" then hit Enter to save and quit

The file looks something simply like this:

runtime
cache
attachments
assets
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文