如何使用 .hgignore 忽略除目录之外的所有目录?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请在
.hgignore
中尝试:^
匹配路径的开头(?!(scripts|foo|bar)
使用负向前瞻来忽略所有文件除了目录scripts
、foo
或bar
中的目录/)
确保以跟踪目录作为前缀的目录被忽略[^/]+/
然后实际上匹配任何目录(不包括那些被前瞻排除的目录),因此~
中的文件不会被忽略此解决方案中的想法(否定前瞻)转到 Michael La Voie 对 的回答这个问题
Try this in
.hgignore
instead:^
matches start of path(?!(scripts|foo|bar)
uses negative lookahead to ignore all files except those in directoriesscripts
,foo
orbar
/)
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 ignoredCredit for the central idea in this solution (the negative lookahead) goes to Michael La Voie's answer to this question
这个问题已经在这里被问过好几次了,你会使用零宽度负前瞻断言得到很多令人费解的答案,这是一种经常被滥用的正则表达式技巧,但更好的解决方案是(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 manuallyhg add
the files you want tracked. In mercurial, unlike svn and cvs, you can override an ignore with an add.