Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

mercurial - How can I ignore all directories except one using .hgignore?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...