忽略 Mercurial 中除特定文件类型的一个或多个文件之外的所有文件?
与 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
或者更好:
它也会匹配奇怪的东西,比如“a..java”或“a.java.java”。
编辑:这是一个修改后的解决方案,结合了 Søren 的技巧和我的一些进一步调整。我希望误报(例如“ajava”或“java”之类的内容没有被忽略)现在得到修复。
Try this:
or better yet:
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.
如果被忽略的模式是可数的,为什么不使用全局模式列表呢?在您忽略回购树中所有 *.class 和 *.java (如果我正确理解任务)的情况下,.hgrc 将是
如果您想忽略具有大量(或可能根本未知)扩展名的所有文件,除了您之外可以尝试在文件定义中使用文件集(
hg help fileets
)。对于您的情况,忽略除 *.png 之外的所有扩展名将会很糟糕。就像(TBT!)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
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!)