使用Glob语法忽略Mercurial中的文件

时间:2022-09-01 22:56:16

I'm using Mercurial and I have a following structure:

我正在使用Mercurial,我有以下结构:

files
   test
       demo.jpg
       video.flv
       video.doc

   sport
       demo2.jpg
       picture.jpg
       text.txt
demo3.jpg
demofile3.doc

I want to make a glob filter that only ignore all "jpg" files in all directory that are children of "files" directory

我想创建一个glob过滤器,它只忽略所有目录中作为“files”目录子项的所有“jpg”文件

I tried with files/*.jpg but it doesn't work.

我试过文件/ * .jpg,但它不起作用。

Any advice would be appreciated.

任何意见,将不胜感激。

3 个解决方案

#1


16  

Regexp solution


This works for me ..

这对我有用..

syntax: regexp
files/.*/.*jpg


Your own solution looks more like a glob. The trick with that is to use the ** syntax to allow for sub directories. See this ...

你自己的解决方案看起来更像是一个glob。其中的诀窍是使用**语法来允许子目录。看到这个......

Glob solution


This glob works for me too

这个glob也适合我

**/files/**/*.jpg


Comments

Personally I'd always go with the glob syntx for this kind of problem. Once you know about the ** syntax, it's easier than a regexp to follow what the pattern is trying to do.

就个人而言,我总是会使用glob syntx来解决这类问题。一旦你了解了**语法,就比正则表达式更容易遵循模式试图做的事情。

#2


11  

If you are happy to ignore "all JPG files inside any directory named files", then use

如果您乐意忽略“名为files的任何目录中的所有JPG文件”,请使用

syntax: glob
files/**.jpg

See hg help patterns which explains that ** is a glob operator that spans directory separators. This means that the file

请参阅hg帮助模式,它解释了**是跨越目录分隔符的glob运算符。这意味着该文件

 files/test/demo.jpg

is matched by files/**.jpg.

匹配文件/ **。jpg。

However, note that glob patterns are not rooted. This means that a file named

但请注意,glob模式不是root。这意味着一个名为的文件

 test/files/demo.jpg

will also be ignored since it matches the pattern after you remove the test/ prefix.

也将被忽略,因为它在删除测试/前缀后匹配模式。

You need to use a regular expression if you are concerned with this. In that syntax, the pattern reads

如果您对此有疑问,则需要使用正则表达式。在该语法中,模式读取

syntax: regex
^files/.*\.jpg

I would normally not worry about rooting the pattern -- I prefer the simplicity of the glob patterns. But it's nice to know that you can root a ignore pattern if you really have to.

我通常不会担心根模式 - 我更喜欢glob模式的简单性。但是很高兴知道如果你真的需要你可以根据忽略模式。

#3


0  

Does it have to be glob syntax? If you use regex syntax, files/.*\.jpg should work.

它必须是glob语法吗?如果你使用正则表达式语法,文件/.* \ .jpg应该工作。

#1


16  

Regexp solution


This works for me ..

这对我有用..

syntax: regexp
files/.*/.*jpg


Your own solution looks more like a glob. The trick with that is to use the ** syntax to allow for sub directories. See this ...

你自己的解决方案看起来更像是一个glob。其中的诀窍是使用**语法来允许子目录。看到这个......

Glob solution


This glob works for me too

这个glob也适合我

**/files/**/*.jpg


Comments

Personally I'd always go with the glob syntx for this kind of problem. Once you know about the ** syntax, it's easier than a regexp to follow what the pattern is trying to do.

就个人而言,我总是会使用glob syntx来解决这类问题。一旦你了解了**语法,就比正则表达式更容易遵循模式试图做的事情。

#2


11  

If you are happy to ignore "all JPG files inside any directory named files", then use

如果您乐意忽略“名为files的任何目录中的所有JPG文件”,请使用

syntax: glob
files/**.jpg

See hg help patterns which explains that ** is a glob operator that spans directory separators. This means that the file

请参阅hg帮助模式,它解释了**是跨越目录分隔符的glob运算符。这意味着该文件

 files/test/demo.jpg

is matched by files/**.jpg.

匹配文件/ **。jpg。

However, note that glob patterns are not rooted. This means that a file named

但请注意,glob模式不是root。这意味着一个名为的文件

 test/files/demo.jpg

will also be ignored since it matches the pattern after you remove the test/ prefix.

也将被忽略,因为它在删除测试/前缀后匹配模式。

You need to use a regular expression if you are concerned with this. In that syntax, the pattern reads

如果您对此有疑问,则需要使用正则表达式。在该语法中,模式读取

syntax: regex
^files/.*\.jpg

I would normally not worry about rooting the pattern -- I prefer the simplicity of the glob patterns. But it's nice to know that you can root a ignore pattern if you really have to.

我通常不会担心根模式 - 我更喜欢glob模式的简单性。但是很高兴知道如果你真的需要你可以根据忽略模式。

#3


0  

Does it have to be glob syntax? If you use regex syntax, files/.*\.jpg should work.

它必须是glob语法吗?如果你使用正则表达式语法,文件/.* \ .jpg应该工作。