2010-11-26 38 views
3

我使用空的.hg_keep文件在Mercurial中保留一些(否则为空)文件夹。除.hg_keep之外的所有文件的正则表达式。

问题是,我找不到一个除.hg_keep文件以外的其他所有工作正则表达式。

让我们说我们有这个filestructure:

a/b/c2/.hg_keep 
a/b/c/d/.hg_keep 
a/b/c/d/file1 
a/b/c/d2/.hg_keep 
a/b/.hg_keep 
a/b/file2 
a/b/file1 
a/.hg_keep 
a/file2 
a/file1 

,我只想保持a/b/.hg_keep文件。

http://gskinner.com/RegExr/的帮助下,我创建了以下.hgignore

syntax: regexp 
.*b.*/(?!.*\.hg_keep) 

但水银忽略的b子文件夹中的所有文件.hg_keep

# hg status 
? .hgignore 
? a/.hg_keep 
? a/b/.hg_keep 
? a/file1 
? a/file 

# hg status -i 
I a/b/c/d/.hg_keep 
I a/b/c/d/file1 
I a/b/c/d2/.hg_keep 
I a/b/c2/.hg_keep 
I a/b/file1 
I a/b/file2 

我知道我一罐hd add所有.hg_keep文件,但有一个正则表达式(或水珠)的解决方案?

回答

1

在您使用正则表达式是什么背景,但是这应该是它不太清楚,这个匹配所有行.hg_keep结束:

^.*\.hg_keep$ 

编辑:这里是一个正则表达式匹配不匹配的项目上述表达式:

^(?:(?!.*\.hg_keep).)*$ 
+0

这些都是他需要不匹配的唯一行 - 这是为.hgignore文件。 – robert 2010-11-26 12:18:42

+0

@robert谢谢,更新包括不匹配的正则表达式。 – 2010-11-26 12:26:06

0

尝试(?!.*/\.hg_keep$)

3

正则表达式否定可能适用于此。如果你想不顾一切除了a/b/.hg_keep文件,你也许可以使用:

^(?!a/b/\.hg_keep)$ 

说事这个正则表达式的部分是:

^     anchor the match to the beginning of the file path 
(?! ...)   negation of the expression between '!' and ')' 
a/b/\.hg_keep  the full path of the file you want to match 
$     anchor the match to the end of the file path 

正则表达式

^a/b/\.hg_keep$ 

将匹配只有该文件称为a/b/.hg_keep

其否定

^(?!a/b/\.hg_keep)$ 

会匹配一切。

0

寻找类似于此的东西。 找到了答案,但这不是我们想要听到的。

  • 限制
  • 没有直接的方式忽略所有但一组文件。尝试使用反转正则表达式匹配将与其他模式组合时失败。这是一个有意的限制,因为替代格式都被认为很可能会让用户感到困惑,因为它们值得额外的灵活性。

    编号:https://www.mercurial-scm.org/wiki/.hgignore

    相关问题