2010-11-26 69 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

    相關問題