如何让 Mercurial 忽略任何扩展名为 .xxx 的文件

发布于 2024-11-08 03:04:23 字数 240 浏览 3 评论 0原文

我希望 Mercurial 忽略具有特定扩展名的任何文件。

例如,我想忽略扩展名为 .SUO 的文件。 (无需对 Visual Studio 用户设置进行版本控制。)

因此,我将 .hgignore 文件更改为:

syntax: glob
*.suo

但是,这没有任何效果,Mercurial 仍然可以看到我的 .suo 文件。

我在这里做错了什么?

I want Mercurial to ignore any file with a certain extension.

For example, I wanted to ignore files with a .SUO extension. (There's no need to version-control Visual Studio user settings.)

So I changed my .hgignore file to this:

syntax: glob
*.suo

However, this has no effect, and Mercurial still sees my .suo file.

What am I doing wrong here?

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

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

发布评论

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

评论(4

皇甫轩 2024-11-15 03:04:23

如果在更改 .hgignore 文件之前运行 hg status 时,.suo 文件前面有一个 ?,那么现在应该忽略它。如果有其他内容(例如 MA),它已经被存储库跟踪,并且不会神奇地停止跟踪。在这种情况下,您需要对文件执行 hg remove 来删除它并让 hg 停止跟踪它,或者只对文件执行 hg忘记 来让 hg 停止跟踪它但保留文件。两者之一之后都应该有一个提交。

如果路径与 .hgignore 文件中的模式匹配,则唯一将从状态列表中省略的文件是未跟踪的文件。忽略被跟踪的文件是没有意义的,因为您永远不会看到它是否已被修改、添加或删除。

编辑:Mercurial 只跟踪文件(您不能让它跟踪空目录),但 .hgignore 中的模式只是针对相对于存储库根目录的文件路径字符串运行。与运行 hg status 时显示的相对路径完全相同。因此,它确实可以按照您所说的方式工作,因为以下几行是我自己的 .hgignore 文件的标准部分:

syntax: glob
*\obj\*
*\bin\*
*.csproj.user
*.suo

同样,当您运行 hg status 并且它显示一个 .suo 文件时,什么单个字符位于该行的开头?它是 MAR!? 字符吗?其后的路是什么?

If, when running hg status before altering your .hgignore file, the .suo file had a ? in front of it, then it should be ignored now. If anything else (M or A for example) it is already tracked by the repository and will not magically stop being tracked. In such a case you'll need to do hg remove on the file to delete it and have hg stop tracking it, or just do hg forget on it to have hg stop tracking it but keep the file. Either should be followed by a commit.

The only files that will be omitted from the status listing if their path matches a pattern in the .hgignore file are files that are not tracked. It would make no sense to omit a file that is tracked, because you would never see whether it had been modified, added, or removed.

Edit: Mercurial does only track files (you can't make it track empty directories), but the patterns in .hgignore are simply run against strings of the file paths relative to the root of the repository. The very same relative paths that it shows you when you run hg status. So it does work how you say you want it to work because the following lines are a standard part of my own .hgignore files:

syntax: glob
*\obj\*
*\bin\*
*.csproj.user
*.suo

Again, when you run hg status and it shows a .suo file, what single character is at the beginning of that line? Is it a M, A, R, ! or ? character? What is the path after it?

简单爱 2024-11-15 03:04:23

Mercurial 使用名为 .hgignore 的文件中的条目来确定它完全忽略哪些文件。它通常位于存储库的根文件中(而不是您可能认为的 .hg 目录中)。

您可以在此处了解更多信息:

http://www.selenic.com/mercurial/hgignore。 5.html

通常,我们使用正则表达式语法来确保大小写不是扩展中的一个因素:

# use regexp syntax.
syntax: regexp
(?i)\.dcu
(?i)\.identcache
(?i)\.dof
(?i)\.dsk
(?i)\.bak
(?i)\.old

这样,它可以确保即使由于某种原因扩展的大小写发生变化,它仍然被忽略。

Mercurial uses entries in a file called .hgignore to determine what files it completely ignores. It is normally located in the root file for your repository (and not in the .hg directory, which you might think).

You can find out more here:

http://www.selenic.com/mercurial/hgignore.5.html

Normally, we use regular expression syntax to ensure that case is not a factor in extensions:

# use regexp syntax.
syntax: regexp
(?i)\.dcu
(?i)\.identcache
(?i)\.dof
(?i)\.dsk
(?i)\.bak
(?i)\.old

That way, it ensures that even if for some reason the case of the extension changes, it is still ignored.

眼泪都笑了 2024-11-15 03:04:23

忽略/排除带有 .o 扩展名的文件的示例:

.*\.o$

对于 .suo 扩展名,应转换为 .*\.suo$
我已经成功地使用了这个方法

Example for ignoring/excluding files with .o extension:

.*\.o$

should translate to .*\.suo$ for .suo extensions.
I have used this method successfully

江心雾 2024-11-15 03:04:23

检查 .hgignore 文件所在位置并确保它位于 $HOME 或项目根文件夹中。检查扩展名的 CASE(对比大小写)。我怀疑模式匹配是否不区分大小写。

编辑:经过测试,模式匹配不区分大小写。因此,如果您想忽略扩展名为“.SUO”的文件,请添加“*.SUO”。

Check where .hgignore file is located and ensure it is either in $HOME or project root folder. Check the CASE (vs case) of the extension. I doubt if pattern matching is case insensitive.

edit: tested, the pattern matching is NOT case sensitive. Hence, add "*.SUO" if you want to ignore files with ".SUO" extension.

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