如何使Mercurial忽略所有隐藏文件? [英] How to make mercurial ignore all hidden files?

查看:85
本文介绍了如何使Mercurial忽略所有隐藏文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我讨厌看到我的存储库中几乎每个目录都列出每个文件两次,一次在文件前面加一个点,一次没有.我尝试将.*添加到我的.hgignore文件中,但是没有任何效果.这是错误的语法吗?更重要的是,首先尝试使用这种方法是个坏主意吗?谢谢.

I hate seeing nearly every directory in my repository list each file twice, once with a dot in front of it and once without. I tried adding .* to my .hgignore file, but it has no effect. Is this the wrong syntax, and more importantly, is it a bad idea to try this in the first place? Thanks.

推荐答案

在gavinb的评论中,您几乎得到了正确的答案,但匹配范围有点宽.但是,RogerPage在评论中再次提供了忽略面部的关键概念(每个人都更喜欢评论而不是答案?).

You've got almost the right answer in the comments from gavinb, but the match was a little to broad. However, key concept about ignoring after the face was provided by RogerPage, again in a comment (what's with everyone preferring comments to answers?).

让我们看一下这9个文件:

Let's look at these nine files:

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的默认正则表达式模式下,您可以这样做:

If in the default regex mode for hgignore you do:

\..*

您忽略了这九个文件中的八个:

You ignore eight of those nine files:

$ 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

比您说的要广泛.它会忽略其中带有任意位置的点.

which is more broad than you said you wanted. It's ignoring anything with a dot anywhere in it.

要忽略所有文件和导演(不是您所说的,而是您想要的),请使用以下正则表达式模式:

To ignore all files and directores (not what you said, but what you seem to want) beginning with a dot you use this regexp pattern:

(^|/)\.

表示文字点之前的内容必须是行(^)的开始或斜线.

which says that the thing before the literal dot has to be the start of the line (^) or a slash.

$ hg stat -i
I .hgignore
I .startwithdot/.filestartwithdot
I .startwithdot/file.with.dots
I .startwithdot/filewithoutdots
I dir.with.dots/.filestartwithdot
I dirwithoutdots/.filestartwithdot

只捕获了以点开头的文件或目录.

That caught only files or directories that start with a dot.

但是,出现的另一个关键概念是.hgignore在添加文件后不起作用.这将防止通配符添加,但是您始终可以使用显式hg add覆盖.hgignore.并且一旦添加了文件,就不再使用hgignore.

However, the other key concept that came up, was that .hgignore has no effect after a file has been added. It will prevent adding by wild card, but you can always override .hgignore with an explicit hg add. and once files have been added the hgignore is no longer consulted.

这实际上非常方便,因为您可以广泛地忽略(例如:.*\.jar),然后添加您确实想要的异常,而不必手动处理hgignore文件.但是,在这种情况下,这意味着您需要hg rm已经意外添加的文件,并且tonfa演示了如何执行此操作(只要文件名中没有空格).

That's actually really handy because you can ignore broadly (ex: .*\.jar) and then add the exceptions you do want manually w/o having to futz with your hgignore file. However, in this case it means you need to hg rm the files you've already added accidentally, and tonfa showed how to do that (so long as there are no spaces in your filenames).

最后,听起来像您想要的.hgignore文件中的内容是:

In the end it sounds like what you want in your .hgignore file is:

(^|/)\._

,您需要删除已经添加的内容:

and that you need to remove the ones you've already added:

find . -type f -name "._*" -print0 |xargs -0 hg rm

这篇关于如何使Mercurial忽略所有隐藏文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆