忽略 Mercurial 中除特定文件类型的一个或多个文件之外的所有文件?

发布于 2024-12-15 04:05:09 字数 1095 浏览 3 评论 0原文

与 gitignore 相同的问题:忽略文件夹中的所有文件除一种特定文件类型之外的层次结构,但适用于 Mercurial。

我希望 .hgignore 忽略除特定文件类型中的一个或多个文件之外的所有文件,例如仅允许 *.java*.class 的文件 要跟踪的文件类型,在当前目录以及子目录中。

例如,在以下目录中:

A.java
a.txt
a.png
A.class
B/C.java
B/G/H/h.png
B/C.class
D/E/F.java

我只想包含以下文件(包括目录结构):(

A.java
A.class
B/C.java
B/C.class
D/E/F.java

是否创建包含 h.png 的目录并不重要.)

我尝试应用和更改上述问题中提到的相同原则(但对于 Mercurial 而言),以及尝试应用问题 如何使用 .hgignore 忽略除一个目录之外的所有目录?,没有任何运气。

编辑:我尝试使用上面提到的目录树进行以下操作,

$ hg stat
? A.class
? A.java
? B/C.class
? B/C.java
? B/G/H/h.png
? D/E/F.java
? a.png
? a.txt
$ hg add -I "**.{class, java}"
adding A.class
adding A.java
adding B/C.class
adding B/C.java
adding D/E/F.java

这给了我想要的结果。如何创建一个 .hgignore 或配置文件,为每个 add 或应用 -I "**.{class, java}" commit(以及类似的查询)?

Identical question to gitignore: Ignore all files in folder hierarchy except one specific filetype, but for Mercurial.

I want .hgignore to ignore all files except one or more files from a specific file type, for instance only allow files of the *.java and *.class file type to be tracked, in the current directory as well as sub directories.

For example, in the following directory:

A.java
a.txt
a.png
A.class
B/C.java
B/G/H/h.png
B/C.class
D/E/F.java

I only want the following files to be included (including the structure of the directories):

A.java
A.class
B/C.java
B/C.class
D/E/F.java

(it does not matter if the directory containing h.png will be created or not.)

I've tried applying and changing the same principles as mentioned in the question above (but for Mercurial instead), as well as trying to apply principles from the question How can I ignore all directories except one using .hgignore?, without any luck.

EDIT: I tried the following with the mentioned directory tree above

$ hg stat
? A.class
? A.java
? B/C.class
? B/C.java
? B/G/H/h.png
? D/E/F.java
? a.png
? a.txt
$ hg add -I "**.{class, java}"
adding A.class
adding A.java
adding B/C.class
adding B/C.java
adding D/E/F.java

which gave me the wanted result. How do I create a .hgignore or config file that applies the -I "**.{class, java}" for each add or commit (and similar queries)?

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

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

发布评论

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

评论(2

倒带 2024-12-22 04:05:09

试试这个:

syntax: regexp
.*\.(?!java$|class$)

或者更好:

syntax: regexp
.*\.(?!java$|.*\.java$|class$|.*\.class$)

它也会匹配奇怪的东西,比如“a..java”或“a.java.java”。

编辑:这是一个修改后的解决方案,结合了 Søren 的技巧和我的一些进一步调整。我希望误报(例如“ajava”或“java”之类的内容没有被忽略)现在得到修复。

syntax: regexp
\.(?!java$|class$)[^.]+$
(?<!\.)java$
(?<!\.)class$

Try this:

syntax: regexp
.*\.(?!java$|class$)

or better yet:

syntax: regexp
.*\.(?!java$|.*\.java$|class$|.*\.class$)

which will also match weird stuff like "a..java" or "a.java.java".

EDIT: Here's a revised solution incorporating Søren's tips and some further tweaking on my part. I hope the false positives e.g. that something like "ajava" or "java" didn't get ignored, are fixed now.

syntax: regexp
\.(?!java$|class$)[^.]+$
(?<!\.)java$
(?<!\.)class$
不打扰别人 2024-12-22 04:05:09

如果被忽略的模式是可数的,为什么不使用全局模式列表呢?在您忽略回购树中所有 *.class 和 *.java (如果我正确理解任务)的情况下,.hgrc 将是

syntax: glob

**.class
**.java

如果您想忽略具有大量(或可能根本未知)扩展名的所有文件,除了您之外可以尝试在文件定义中使用文件集(hg help fileets)。对于您的情况,忽略除 *.png 之外的所有扩展名将会很糟糕。就像(TBT!)

"set:not **.png"

If ignored patterns are countable, why not use list of glob patterns? In your case for ignoring everywhere in repo-tree all *.class and *.java (if I understand task correctly) .hgrc will be

syntax: glob

**.class
**.java

If you want ignore all files with a lot of (or possible unknown at all) extensions except some you can try to use filesets (hg help filesets) in files-definition. Ignoring all extensions except *.png for your case will be smth. like (TBT!)

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