How to ignore a folder except one subfolder in Mercurial

317 Views Asked by At

I'm using Mercurial and I would like to ignore all folders named 'build' (I have two of these), with one exception - I would like to include the folder 'build/outputs/mapping/release'

I tried to add 'build/*' to .hgignore and manually add the subfolder to my repository it using hg add build/outputs/mapping/release but it didn't work.

Any idea how can I do it in my .hgignore file?

1

There are 1 best solutions below

2
torek On

Git supports the concept of "un-ignoring" a previously listed ignore entry, with later entries overriding earlier ones. Mercurial does not, so you must come up with expressions that cover your case.

You mention that you have two particular directories to ignore, so instead of using a pattern, you can simply list them:

^build/ignore1/
^build/ignore2/

for instance. For more complex cases, you can either enumerate them all, or come up with a pattern that matches the desired paths, as you did in your comment.