.hgignore whole directory tree excepting one specific file

无人久伴 提交于 2019-12-06 19:00:52

问题


Can anyone tell me the .hgignore pattern to track one specific file in a directory and to ignore everything else?

I have a "media" directory which contains a "default.png", for obvious purposes, and the rest of the directory will hold user media. We want hg to ignore everything in the media directory excepting the default file.


回答1:


Try:

syntax: regex
^media/.*

or (leave it in the default glob and do)

media/**

and then manually hg add media/default.png.

In mercurial (unlike in CVS) you can add files that match your ignore patterns and they work fine. So ignore broadly and hg add what you want tracked.




回答2:


syntax: regex
^media/(?!default.png$)

almost the same as John Mee's but matches to the end of the line, instead of anything that starts with default.png.

if you wanted to allow any .c file but nothing else, you could use:

^media/(?!.+\.c$)



回答3:


Summing it up as a BKM (Best Known Method)

Either hgignore everything, and then hg add back the few files you want to track.

Or use a pattern such as

syntax: regex
^path/(?!files-that-you-want-not-to-ignore$)

(I just wanted to see the full answer in one place.)




回答4:


Never mind this seems to work...

syntax: regex
^media/(?!default.png)


来源:https://stackoverflow.com/questions/1678091/hgignore-whole-directory-tree-excepting-one-specific-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!