我讨厌看到我的存储库中几乎每个目录都列出每个文件两次,一次在它前面有一个点,一次没有。我尝试添加 .*
到我的 .hgignore 文件,但它没有效果。这是错误的语法,更重要的是,首先尝试这个是个坏主意吗?谢谢。
最佳答案
您在 gavinb 的评论中几乎得到了正确的答案,但匹配范围有点广。然而,RogerPage 再次在评论中提供了关于忽略面部之后的关键概念(每个人都更喜欢评论而不是答案?)。
我们来看看这九个文件:
dir.with.dots/file.with.dots
dir.with.dots/filewithoutdots
dir.with.dots/.filestartwithdot
dirwithoutdots/file.with.dots
dirwithoutdots/filewithoutdots
dirwithoutdots/.filestartwithdot
.startwithdot/file.with.dots
.startwithdot/filewithoutdots
.startwithdot/.filestartwithdot
如果在 hgignore 的默认正则表达式模式下,您会执行以下操作:
\..*
您忽略了这九个文件中的八个:
$ hg stat -i
I .hgignore
I .startwithdot/.filestartwithdot
I .startwithdot/file.with.dots
I .startwithdot/filewithoutdots
I dir.with.dots/.filestartwithdot
I dir.with.dots/file.with.dots
I dir.with.dots/filewithoutdots
I dirwithoutdots/.filestartwithdot
I dirwithoutdots/file.with.dots
这比你说的你想要的更广泛。它忽略带点的任何内容 任何地方 在其中。
忽略所有 文件和目录 (不是你说的,而是你似乎想要的)以一个点开始,你使用这个正则表达式模式:
(^|/)\.
这表示文字点之前的东西必须是行首(
^
)或斜线。$ hg stat -i
I .hgignore
I .startwithdot/.filestartwithdot
I .startwithdot/file.with.dots
I .startwithdot/filewithoutdots
I dir.with.dots/.filestartwithdot
I dirwithoutdots/.filestartwithdot
那只捕获以点开头的文件或目录。
然而,出现的另一个关键概念是 .hgignore 在添加文件后无效。它会阻止通过通配符添加,但您始终可以使用显式
hg add
覆盖 .hgignore .一旦添加了文件,就不再咨询 hgignore。这实际上非常方便,因为您可以广泛地忽略(例如:
.*\.jar
),然后手动添加您想要的异常(exception),而不必对您的 hgignore 文件进行 futz。但是,在这种情况下,这意味着您需要 hg rm
您已经意外添加的文件,tonfa 展示了如何执行此操作(只要您的文件名中没有空格)。最后听起来你想要的 .hgignore 文件是:
(^|/)\._
并且您需要删除已添加的那些:
find . -type f -name "._*" -print0 |xargs -0 hg rm
关于mercurial - 如何让 mercurial 忽略所有隐藏文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2395179/