2013-03-28 65 views

回答

27

如圖所示here並詳細描述在「this question」中,函數fnmatch()涉及解釋glob模式,這意味着不支持正則表達式。

這是gitignore man page提到:

否則,git treats the pattern as a shell glob suitable for consumption by fnmatch(3)FNM_PATHNAME標誌:在模式通配符不匹配的路徑名/
例如,「Documentation/*.html」與「Documentation/git.html」匹配,但不匹配「Documentation/ppc/ppc.html」或「tools/perf/Documentation/perf.html」。

您可以在thosequestions中看到glob模式與正則表達式之間的某些對應關係。

8

.gitignore(和其他)文件使用文件名globs,而不是正則表達式。

我非常懷疑你可以說服git黑客改變這種情況:到現在爲止根深蒂固,而且globs比作爲文件名匹配者更爲熟悉。

+10

很遺憾。這樣一個方便的功能可以。 – 2014-04-17 08:02:31

+3

@ArturBarseghyan,考慮Mercurial,它有這個整潔的功能和許多其他很酷的功能。 – toriningen 2015-04-04 20:46:33

+0

@modchan:我知道它存在於Mercurial中,我使用它很多。無論如何感謝您的評論。 – 2015-04-07 14:29:51