如何使用 .hgignore 忽略除目录之外的所有目录?

发布于 2024-09-17 06:05:27 字数 434 浏览 2 评论 0原文

我正在使用 Mercurial 管理 $HOME,以保持我的点文件的良好和跟踪,或者至少是对我来说重要的点文件。

然而,~ 中有大量不需要跟踪的文件和目录,并且该集合是不断变化和不断增长的。

从历史上看,我通过使用这个 .hgignore 来处理这个问题:

syntax: glob
*

就目前而言,这使我的状态保持干净,只使以前跟踪的文件可见。但是,我有一些目录(在我的例子中是 scripts.emacs.d),我希望在其中看到未跟踪的文件;我几乎总是想要跟踪这些目录的新添加内容。

我知道我可以运行 hg st -u 脚本来识别未跟踪的文件,但我想要一种方法,可以使用普通的 ole hg status 来实现相同的功能。

有办法做到这一点吗?

I'm managing $HOME using Mercurial, to keep my dotfiles nice and tracked, or at least the ones that matter to me.

However, there's a profusion of files and directories in ~ that do not need to be tracked, and that set is ever-changing and ever-growing.

Historically, I've dealt with this by having this .hgignore:

syntax: glob
*

This keeps my status clean, as far as it goes, making only previously tracked files visible. However, I have some directories (in my case, scripts, .emacs.d) that I would like to see untracked files in; I almost always want to track new additions to those directories.

I know that I can run hg st -u scripts to identify untracked files, but I want a means whereby I can achieve the same function using plain ole hg status.

Is there a way to do this?

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

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

发布评论

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

评论(2

人间☆小暴躁 2024-09-24 06:05:27

请在 .hgignore 中尝试:

syntax: regexp

^(?!(scripts|foo|bar)/)[^/]+/
  • ^ 匹配路径的开头
  • (?!(scripts|foo|bar) 使用负向前瞻来忽略所有文件除了目录 scriptsfoobar 中的目录
  • /) 确保以跟踪目录作为前缀的目录被忽略
  • [^/]+/ 然后实际上匹配任何目录(不包括那些被前瞻排除的目录),因此 ~ 中的文件不会被

忽略此解决方案中的想法(否定前瞻)转到 Michael La Voie 对 的回答这个问题

Try this in .hgignore instead:

syntax: regexp

^(?!(scripts|foo|bar)/)[^/]+/
  • ^ matches start of path
  • (?!(scripts|foo|bar) uses negative lookahead to ignore all files except those in directories scripts, foo or bar
  • /) ensures that directories which have a tracked directory as a prefix are ignored
  • [^/]+/ then actually matches any directory (excluding those ruled out by the lookahead), so that files in ~ aren't ignored

Credit for the central idea in this solution (the negative lookahead) goes to Michael La Voie's answer to this question

放肆 2024-09-24 06:05:27

这个问题已经在这里被问过好几次了,你会使用零宽度负前瞻断言得到很多令人费解的答案,这是一种经常被滥用的正则表达式技巧,但更好的解决方案是(a)只是使单独在该目录中的存储库或 (b) 仅在该目录中添加文件。对于选项 (b),您只需将 .* 放入 .hgignore 文件中以忽略所有内容,然后手动 hg add 您想要的文件想要跟踪。在 Mercurial 中,与 svn 和 cvs 不同,您可以使用 add 覆盖忽略。

This question has been asked here on SO quite a few times, and you'll get a lot of convoluted answers using zero-width negative look ahead assertions, an oft abused regex trick, but the better solutions are to either (a) just make the repo in that directory alone or (b) just add the files in that directory. For option (b) you'd just put .* in your .hgignore file to ignore everything, and then manually hg add the files you want tracked. In mercurial, unlike svn and cvs, you can override an ignore with an add.

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