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

发布于 2024-08-24 12:57:24 字数 128 浏览 10 评论 0原文

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幽蝶幻影 2024-08-31 12:57:24

您在 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),然后手动添加您确实想要的异常,而无需使用 hgignore 文件进行操作。但是,在这种情况下,这意味着您需要 hg rm 您已经意外添加的文件,并且 tonfa 展示了如何执行此操作(只要文件名中没有空格)。

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

(^|/)\._

并且您需要删除已经添加的文件:

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

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?).

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

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.

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.

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).

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
就此别过 2024-08-31 12:57:24

我在我的 .hgignore 中使用了这个:

syntax: regexp

# dotfiles
(?<![^/])\.

它的内容是:句点前面除了正斜杠之外没有其他东西。

Ry4an的解决方案也不错,我以前也用过。不确定哪个更有效率。

https://regex101.com/r/dB4bW7/1

I use this in my .hgignore:

syntax: regexp

# dotfiles
(?<![^/])\.

Which reads: periods not preceded by something other than a forward slash.

Ry4an's solution is also good, I've used that one before too. Not sure which is more efficient.

https://regex101.com/r/dB4bW7/1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文