使用 svn:ignore 忽略除某些文件之外的所有内容

发布于 2024-07-26 17:46:19 字数 332 浏览 8 评论 0原文

使用 svn:ignore 属性,有没有一种方法可以根据我不想忽略的模式指定我想要忽略的内容? 换句话说,我想忽略除以 .xyz 结尾的文件之外的所有内容。 我将如何去做(如果可能的话)?

我探索过的一种选择是提交我想要进行版本控制的所有内容,然后将目录上的 svn:ignore 属性设置为“*”,这意味着除了我已经提交的文件之外,不会有其他文件进行版本控制。 这是我能想到的最好的办法,但感觉很脏,因为如果我确实需要添加另一个文件作为版本,我必须进行多次提交......一个删除 svn:ignore 属性,另一个添加/提交新文件,然后第三个将 svn:ignore 更改回“*”。

你的想法?

With the svn:ignore property, is there a way I can specify what I want to ignore based on patterns which I don't want to ignore? In other words, I want to ignore everything but files ending in .xyz. How would I go about doing that (if it's even possible)?

One option I've explored is committing everything I want to be versioned, then setting the svn:ignore property on the directory to be '*', thus meaning no other files but what I've already committed will be versioned. This is the best I can come up with, but it feels dirty in that if I ever did need to add another file to be version, I'd have to make multiple commits... one to remove the svn:ignore property, another to add/commit the new file(s), and then a third to change svn:ignore back to '*'.

Your thoughts?

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

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

发布评论

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

评论(6

蒲公英的约定 2024-08-02 17:46:19

看看 对 Subversion 的 svn 使用否定模式:忽略属性。 显然你可以使用“!” 在字符组中否定其含义。 因此,如果您想忽略除以 .java 结尾的文件之外的所有内容,请将以下模式设置为 svn:ignore:

*[!j][!a][!v][!a]
*.java?*

Have a look at Using negative patterns for Subversion's svn:ignore property. Obviously you can use "!" in character groups to negate its meaning. So if you want to ignore everything except files ending with .java, set the following pattern to svn:ignore:

*[!j][!a][!v][!a]
*.java?*
不顾 2024-08-02 17:46:19

不,不存在您所描述的独家匹配。 本文列出了模式匹配。 它仅限于:

  • ? - 匹配任何单个字符
  • * - 匹配任何字符串,包括空字符串
  • [ - 开始字符类定义由 ] 终止,用于匹配字符子集

类似的问题已经被问过

No, there is no exclusive matching like you described. This article lists the possibilities for pattern matching. It's limited to:

  • ? - Matches any single character
  • * - Matches any string of characters, including the empty string
  • [ - Begins a character class definition terminated by ], used for matching a subset of characters

A similar question was asked already here.

草莓酥 2024-08-02 17:46:19

这是我所知道的唯一解决方案。 即使文件被忽略,您也可以显式添加它们。

不过,您需要在所有子目录中添加该设置。

# Create a repository with property ignore *

[wlynch@orange ~] cd /tmp
[wlynch@orange /tmp] svnadmin create foo
[wlynch@orange /tmp] svn co file:///tmp/foo co
Checked out revision 0.
[wlynch@orange /tmp] cd co
[wlynch@orange co] svn propset svn:ignore \* .
property 'svn:ignore' set on '.'

# Create 3 files

[wlynch@orange co] touch a
[wlynch@orange co] touch b
[wlynch@orange co] touch c

# We can add all 3 of these files in one transaction

[wlynch@orange co] svn status
M     .
[wlynch@orange co] svn add a
A         a
[wlynch@orange co] svn add b
A         b
[wlynch@orange co] svn status
M     .
A      a
A      b
[wlynch@orange co] svn add c
A         c
[wlynch@orange co] svn ci
Sending        .
Adding         a
Adding         b
Adding         c
Transmitting file data ...
Committed revision 1.

That's the only solution I know of. You can explicitly add files even if they are ignored though.

You would need to add that setting on all subdirectories though.

# Create a repository with property ignore *

[wlynch@orange ~] cd /tmp
[wlynch@orange /tmp] svnadmin create foo
[wlynch@orange /tmp] svn co file:///tmp/foo co
Checked out revision 0.
[wlynch@orange /tmp] cd co
[wlynch@orange co] svn propset svn:ignore \* .
property 'svn:ignore' set on '.'

# Create 3 files

[wlynch@orange co] touch a
[wlynch@orange co] touch b
[wlynch@orange co] touch c

# We can add all 3 of these files in one transaction

[wlynch@orange co] svn status
M     .
[wlynch@orange co] svn add a
A         a
[wlynch@orange co] svn add b
A         b
[wlynch@orange co] svn status
M     .
A      a
A      b
[wlynch@orange co] svn add c
A         c
[wlynch@orange co] svn ci
Sending        .
Adding         a
Adding         b
Adding         c
Transmitting file data ...
Committed revision 1.
信仰 2024-08-02 17:46:19

这是我在 bin 文件夹中为 svn:ignore 属性设置的内容,以匹配除 apk 文件之外的所有内容:

*[!a][!p][!k]
*a[!p][!k]
*ap[!k]

如果有完整的 RegExp 支持,您可以使用负向后查找,但那就是无论如何很少实现(例如不在 JavaScript 中)并且效率低下。

This is what I have set on bin folder for svn:ignore property to match everything except apk files:

*[!a][!p][!k]
*a[!p][!k]
*ap[!k]

If there would be full RegExp support you could use negative lookbehind, but that's rarely implemented anyway (e.g not in JavaScript) and is inefficient.

寄与心 2024-08-02 17:46:19

以下内容对我有用,并消除了其他建议的一些怪癖。

*.?
*.??
*.???
*.[!j]???
*.?[!a]??
*.??[!v]?
*.???[!a]
*.?????*

逐行解释如下:

  • 忽略具有一个字母扩展名的所有内容
  • 忽略具有两个字母扩展名的所有内容
  • 忽略具有三个字母扩展名的所有内容
  • 忽略具有四个字母扩展名的所有内容,其中扩展名的第一个字母不是j
  • 忽略具有四字母扩展名的所有内容,其中扩展名的第二个字母不是 a
  • 忽略具有四字母扩展名的所有内容,其中扩展名的第三个字母不是 v
  • 忽略具有四字母扩展名的所有内容,其中扩展名的第四个字母是不是
  • 忽略具有五个字母或更多字母扩展名的所有

内容限制:

  • 这也会阻止以 .java 结尾的目录
  • 不幸的是我无法忽略没有扩展名的文件,因为这也会阻止目录。

The following works for me and gets rid of a few quirks of the other suggestions.

*.?
*.??
*.???
*.[!j]???
*.?[!a]??
*.??[!v]?
*.???[!a]
*.?????*

A line by line explanation follows:

  • ignore everything that has a one-letter extension
  • ignore everything that has a two-letter extension
  • ignore everything that has a three-letter extension
  • ignore everything that has a four-letter extension where the extension's first letter is not j
  • ignore everything that has a four-letter extension where the extension's second letter is not a
  • ignore everything that has a four-letter extension where the extension's third letter is not v
  • ignore everything that has a four-letter extension where the extension's fourth letter is not a
  • ignore everything that has a five-letter extension or more

Limitations:

  • This will also block directories that end on .java
  • Unfortunately I was not able to ignore files without extension, since that would also block directories.
往事随风而去 2024-08-02 17:46:19

好吧,我不知道我是否错过了一些东西,但是您可以使用您想要的任何模式:

svn propset svn:ignore "*~" .

您可以检查:

svn propget svn:ignore .

另一种方法是使用可以在提交时进行复杂解析的别名/脚本。

我发现自己使用的最佳解决方案是将源文件的版本树与构建树完全分离。 这样,您就不会在目录的版本树中生成内容。 那么你只能使用 svn:ignore 来忽略由文本编辑器生成的简单人工制品。

编辑:

抱歉我对第一个解决方案的错误,我误读了你的帖子。 即使不完全是您想要的,其他两种方式似乎也相关......

Well, I don't know if I miss something, but you can use any pattern you want:

svn propset svn:ignore "*~" .

You can check with:

svn propget svn:ignore .

Another way is to use an alias / script that can do complex parsing when committing.

The best solution I find to use myself is to completely separate the versioned tree of source files from the build tree. This way you do not generate things in your versioned tree of a directory. Then you can only use svn:ignore to ignore simple artefacts generated by text editors for example.

EDIT:

Sorry my mistake for the first solution, I have misread your post. The two other ways seems relevant even if not exactly what you want...

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