本文介绍了Mercurial .hgignore负前瞻的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Mercurial,除了在某个名为"keepers"的目录中的文件外,我需要忽略所有文件.

Using Mercurial, I need to ignore all files except for those in a certain directory called "keepers".

表面上,使用Regex和Negative Lookahead似乎很容易;但是,尽管我可以在Regex Buddy和其他工具中验证我的正则表达式,但是在TortoiseHg中,它却无法按预期工作.

On the face of things, this seemed easy using Regex and Negative Lookahead; however, although I am able to verify my regex in Regex Buddy and other tools, in TortoiseHg, it doesn't work as expected.

文件:

  • junk \ junk.txt
  • 垃圾\文本
  • keepers \ test \ test
  • keepers \ test \ test2 \ hi.txt
  • keepersblah.txt

只有在Keepers下的两个文件不应该被忽略.

Only the two files under keepers should be not be ignored.

这是我希望可以使用的正则表达式:

Here is the regex I hoped would work:

^(?!keepers/).+$

遗憾的是,这将导致所有文件被忽略.如果我将其更改为:

Regrettably, this causes all files to be ignored. If I change it to:

^(?!keepers).+$

它可以按您期望的那样工作.那就是它会忽略所有不是以keepers开头的文件/文件夹.但是我确实想忽略以管家开头的文件.

it works as you would expect. That is it ignores any files/folders that don't start with keepers. But I do want to ignore files that start with keepers.

怪诞的,如果我将其更改为此:

Bizarrely, if I change it to this:

^(?!keepers/).+\..+$

它将正确匹配该文件夹,但是如果没有扩展名,它将不会忽略不在keepers文件夹中的文件.

It will properly match the folder, but it will not ignore files that are not in the keepers folder if they don't have an extension.

任何建议将不胜感激.

删除无效的ImageShack链接

推荐答案

第一个表达式的问题是正则表达式也针对"keepers"本身进行了测试.可以在附加条件下添加该案例:

The problem with your first expression is that the regex is also tested against "keepers" itself. That case can be added with an additional condition:

^(?!keepers(?:/|$))

或(不太紧凑,但更易于理解):

or (less compact, but simpler to understand):

^(?!keepers/|keepers$)

这篇关于Mercurial .hgignore负前瞻的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 00:27