.hgignore whole directory tree excepting one specific file
Asked Answered
B

4

17

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.

Bonaparte answered 5/11, 2009 at 3:9 Comment(0)
D
25

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.

Dickman answered 5/11, 2009 at 3:55 Comment(2)
this does work however it requires you to manually add the files you want and hg will not notice if you add a new file that matches the pattern (if you matched on *.c for example).Stuccowork
Entirely true. I still prefer it to the negative-look-ahead stuff, but not everyone does. Personally I just make sure my transitory files and my stuff-to-keep end up in different directories so I don't have to worry about it.Dickman
S
6
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$)
Stuccowork answered 7/3, 2012 at 17:46 Comment(0)
H
5

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.)

Hanging answered 3/6, 2012 at 20:6 Comment(1)
How do I specify multiple files?Disintegration
B
4

Never mind this seems to work...

syntax: regex
^media/(?!default.png)
Bonaparte answered 5/11, 2009 at 3:17 Comment(2)
this would also match default.png.sadkjsdhfdshfjkdsStuccowork
yeah, needs a '$' on the end to be sure. see your answer.Bonaparte

© 2022 - 2024 — McMap. All rights reserved.