How to ignore all the directories but include some?

I want to ignore /foo but not /foo/bar but it just ignore everything in foo.

/foo
!/foo/bar

I doesn’t work for me. I think this kinds of overwriting works in gitignore. Am I doing something wrong or the syntax is different with what I have in mind. I could not find anything in documentation page. Is there a solution to have what I described?

The order matters, afaik it’s a ‘first match counts’-system (top-down). In general, includes should come before more general ignore-rules.

1 Like

Yeah it works now. Didn’t expect that.

Just for reference, from the “Patterns” section of Syncthing’s Ignoring Files documentation page:

The .stignore file contains a list of file or path patterns. The first pattern that matches will decide the fate of a given file.

Git’s gitignore is the reverse, with the last pattern match taking precedence.

1 Like