un-ignore subfolders & files of ignored folder

Including a subdirectory explicitly is possible:

!/projects/project1
/projects/
!/projects

*

I think will do what you want but some might find the syntax is, well, a little ugly.

The [ignore patterns discussion] (https://forum.syncthing.net/t/excluding-files-from-synchronization-ignoring/80/21) cites [.gitignore] (Git - gitignore Documentation), which rather puzzled me as I didn’t see git and syncthing as comparable.

I’ve used git a fair bit but never have had any trouble setting up ignores rules like I have had with sycnthing and I have never used the ! syntax to ‘un-exclude’ something. So I read the reference. I’ve always used .gitignore files ‘within the repository’ and I can see how the ! syntax could be useful. However, I’ve never really used gitignore rules ‘outside the repository’, which is, I guess, analogous with the syncthing use case. I see that as a very different use case and ! syntax as problematical.

Is syncthing trying to emulate gitnore ? Sadly not. Among the differences are that with github the ! syntax “any matching file excluded by a previous pattern will become included again” so the ! rule appears second, whereas with syncthing it must appear first.

Another difference that I am not the only one to find confusing is the interpretation of name/. Plain name matches either a file or a directory. To gitignore, and to me, name/ matches a directory but not a file. However, in syncthing name/ matches the contents of the directory but not the directory itself. It is the same as name/* :scream: ) . The difference is subtle:

!/projects/project1/
/projects/*
!/projects/

*

does not mean at all what you might think it should (even though to my mind it expresses the intent more clearly).

Can the (first) example be extended to second and third level directories ? Yes but the tedium increases with every level:

!/projects/project1/workpackage24/task7
/projects/project1/workpackage24/
!/projects/project1/workpackage24
/projects/project1/
!/projects/project1
/projects/
!/projects
*

This works but I spent an entire weekend setting up my .stignore file to include what I wanted and exclude what I didn’t want and test the damned configuration.

If I ever have to do this again (and I really hope I don’t) I’ll write a script to pre-process a .stignore file from one that has simple (one-line) include rules into one with slews of rules required by syncthing.

In the end, software is so much better at this kind of thing than we are and you just have to wonder why syncthing can’t do it for us.

2 Likes