问题描述
我正在使用Mercurial管理$ HOME,以保持点文件的良好状态和可跟踪性,或者至少对我来说很重要.
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.
从历史上看,我已经通过使用以下.hgignore来解决了这个问题:
Historically, I've dealt with this by having this .hgignore:
syntax: glob
*
这将使我的状态保持尽可能的整洁,仅使以前跟踪的文件可见.但是,我有一些目录(在我的情况下为scripts
,.emacs.d
),我希望在其中查看未跟踪的文件.我几乎总是要跟踪这些目录中的新内容.
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.
我知道我可以运行hg st -u scripts
来识别未跟踪的文件,但是我想要一种可以使用普通ole hg状态实现相同功能的方法.
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?
推荐答案
请在.hgignore
中尝试此操作:
syntax: regexp
^(?!(scripts|foo|bar)/)[^/]+/
-
^
匹配路径的开头 -
(?!(scripts|foo|bar)
使用负前行忽略所有文件,但目录scripts
,foo
或bar
中的文件除外 -
/)
确保以跟踪目录作为前缀的目录被忽略 -
[^/]+/
然后实际上匹配任何目录(不包括先行排除的目录),这样就不会忽略~
中的文件 ^
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 ignored
此解决方案中的中心思想的信用(否定的前瞻性)归功于Michael La Voie对
Credit for the central idea in this solution (the negative lookahead) goes to Michael La Voie's answer to this question
这篇关于如何忽略除.hgignore以外的所有目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!