.hgignore 语法仅忽略文件,而不忽略目录?
我有一个我似乎无法理解的问题。 我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 irc.freenode.net 上的
#mercurial
中转发了这个问题,得到的答复是您无法区分文件和目录 - 该目录在没有您在正则表达式中搜索的斜杠的情况下进行匹配。但是,如果您可以假设您的目录永远不会包含句号
.
,但您的文件会包含句号,那么类似这样的操作似乎可以工作:我在这样的存储库中测试了它:
添加 < code>.hgignore 文件给出:
表示根目录中的
a.txt
文件被正确忽略,但中的
子目录不是。 您还可以看到根目录中名为x.txt
文件被忽略。 foobbb
的文件没有被忽略。 但也许您可以自己将此类文件添加到.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:
Adding the
.hgignore
file gives:which indicates that the
a.txt
file is correctly ignored in your root directory, butx.txt
in thefoo
subdirectory is not. You can also see that a file named justbbb
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.这里有一个肮脏的技巧:
在目录中创建一个空文件“.hidden”,然后添加到 .hgignore:
这将忽略目录中除“.hidden”之外的所有文件。
Here is a dirty trick:
Create an empty file ".hidden" in your directory, than add to .hgignore:
This will ignore all files in the directory except ".hidden".