.hgignore 语法仅忽略文件,而不忽略目录?

发布于 2024-07-25 23:27:26 字数 529 浏览 3 评论 0原文

我有一个我似乎无法理解的问题。 我在 Windows 上使用 TortoiseHg(版本 0.7.5),但在 Linux 上我遇到了同样的问题。 这是:

我的 .hgignore 文件:

syntax: regexp
^[^\\/]+$

我想要实现的目标是将 hg 存储库根目录中的文件添加到忽略列表中。

例如,如果我有这样的:

.hg
+mydir1
+mydir2
-myfile1
-myfile2
-anotherfile1
-anotherfile2 
.hgignore

我希望忽略 myfile1(2) 和 anotherfile1(2) (名称仅用于此示例的目的 - 它们没有可以轻松放入 hgignore 文件中的简单规则)

有没有我遗漏的东西,因为我很确定正则表达式很好(我什至测试了它)? 有想法吗?

有没有更简单的方法来实现这一目标? [添加到 Mercurial 存储库根目录中的忽略列表文件]

I have a problem which I can't seem to understand. I'm using TortoiseHg (version 0.7.5) on Windows but on Linux I have the same problem. Here it is:

My .hgignore file:

syntax: regexp
^[^\\/]+$

What I'm trying to achieve is to add to the ignore list the files which are in the root of the hg repository.

For example if I have like this:

.hg
+mydir1
+mydir2
-myfile1
-myfile2
-anotherfile1
-anotherfile2 
.hgignore

I want myfile1(2) and anotherfile1(2) to be ignored (names are only for the purpose of this example - they don't have a simple rule that can be put in the hgignore file easily)

Is there something I'm missing because I'm pretty sure that regexp is good (I even tested it)? Ideas?

Is there a simpler way to achieve this? [to add to the ignore list files that are in the root of the mercurial repository]

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

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

发布评论

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

评论(2

a√萤火虫的光℡ 2024-08-01 23:27:26

我在 irc.freenode.net 上的 #mercurial 中转发了这个问题,得到的答复是您无法区分文件和目录 - 该目录在没有您在正则表达式中搜索的斜杠的情况下进行匹配。

但是,如果您可以假设您的目录永远不会包含句号 .,但您的文件会包含句号,那么类似这样的操作似乎可以工作:

^[^/]*\..*$

我在这样的存储库中测试了它:

% hg status -ui
? a.txt
? bbb
? foo/x.txt
? foo/yyy

添加 < code>.hgignore 文件给出:

% hg status -ui
? bbb
? foo/x.txt
? foo/yyy
I .hgignore
I a.txt

表示根目录中的 a.txt 文件被正确忽略,但 中的 x.txt 文件被忽略。 foo 子目录不是。 您还可以看到根目录中名为 bbb 的文件没有被忽略。 但也许您可以自己将此类文件添加到 .hgignore 文件中。

如果您的根目录中碰巧有像 bar.baz 这样的目录,那么该目录及其中的所有文件都将被忽略。 我希望这个能有一点帮助。

I relayed this question in #mercurial on irc.freenode.net and the response was that you cannot distinguish between files and directories — the directory is matched without the slash that you're searching for in your regexp.

However, if you can assume that your directories will never contain a full-stop ., but your files will, then something like this seems to work:

^[^/]*\..*$

I tested it in a repository like this:

% hg status -ui
? a.txt
? bbb
? foo/x.txt
? foo/yyy

Adding the .hgignore file gives:

% hg status -ui
? bbb
? foo/x.txt
? foo/yyy
I .hgignore
I a.txt

which indicates that the a.txt file is correctly ignored in your root directory, but x.txt in the foo subdirectory is not. You can also see that a file named just bbb in the root directory is not ignored. But maybe you can add such files yourself to the .hgignore file.

If you happen to have a directory like bar.baz in your root directory, then this directory and all files within will be ignored. I hope this helps a bit.

撩发小公举 2024-08-01 23:27:26

这里有一个肮脏的技巧:

在目录中创建一个空文件“.hidden”,然后添加到 .hgignore:

^mydir/(?!\.hidden).+$

这将忽略目录中除“.hidden”之外的所有文件。

Here is a dirty trick:

Create an empty file ".hidden" in your directory, than add to .hgignore:

^mydir/(?!\.hidden).+$

This will ignore all files in the directory except ".hidden".

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