mercurial - 如何让 mercurial 忽略所有隐藏文件?

标签 mercurial dvcs glob hgignore

我讨厌看到我的存储库中几乎每个目录都列出每个文件两次,一次在它前面有一个点,一次没有。我尝试添加 .*到我的 .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/

相关文章:

git - 令人困惑的 .gitignore 语法

windows - Mercurial 可以从 Windows 创建自己的符号链接(symbolic link)格式吗?

mercurial - 在 Mercurial 中提交和回滚后恢复丢失的文件。 (相当于 git reflog?)

svn - 在本地使用Mercurial,仅用于Subversion服务器

mercurial - 为什么 Mercurial 需要与服务器通信以列出传出(非推送)提交?

javascript - Grunt 将带点的文件夹视为文件

regex - Bash 正则表达式 : Matching numbers 0-1000

mercurial - 使用Mercurial,如果有额外的分支,我们是否需要 "hg merge -r 6880"?

version-control - 离线源代码管理

java - 如何使用 Java glob 模式搜索(区分大小写)文件?