Mercurial .hgignore 负向前瞻
使用 Mercurial,我需要忽略除名为“keepers”的某个目录中的文件之外的所有文件。
从表面上看,使用 Regex 和 Negative Lookahead 似乎很容易;然而,尽管我能够在 Regex Buddy 和其他工具中验证我的正则表达式,但在 TortoiseHg 中,它无法按预期工作。
文件:
- junk\junk.txt
- junk\text
- keepers\test\test
- keepers\test\test2\hi.txt
- keepersblah.txt
只有keepers下的两个文件不应该被忽略。
这是我希望起作用的正则表达式:
^(?!keepers/).+$
遗憾的是,这会导致所有文件被忽略。如果我将其更改为:
^(?!keepers).+$
它会按您的预期工作。也就是说,它会忽略任何不以 keeper 开头的文件/文件夹。但我确实想忽略以 keeper 开头的文件。
奇怪的是,如果我将其更改为:
^(?!keepers/).+\..+$
它将正确匹配文件夹,但如果它们没有扩展名,则不会忽略不在 keepers 文件夹中的文件。
任何建议将不胜感激。
删除失效的 ImageShack 链接
Using Mercurial, I need to ignore all files except for those in a certain directory called "keepers".
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.
Files:
- junk\junk.txt
- junk\text
- keepers\test\test
- keepers\test\test2\hi.txt
- keepersblah.txt
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).+$
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/).+\..+$
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.
Any advice would be appreciated.
removing dead ImageShack link
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的第一个表达式的问题是正则表达式还针对“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:
or (less compact, but simpler to understand):