Possible to have a .stignore in nested folders?

This question has been asked before but the threads are old now, so ask again in case things have changed.

I am entirely new to ST. I want to sync an entire partition and will create a .stignore file in the root of that partition. However, I am wondering if I can put a .stignore file in a couple of folders, and sub-folders, of that partition so that those folders will have their own specific ‘ignore’ and ‘include’ preferences. Will this work for these specific folders? Or is it really necessary to just have a single (‘global’ I guess it would be called) .stignore in the root of the partition?

Also a subsidiary question: Does the .stignore file on one computer have to be precisely replicated on the other computer? Please ignore this question I found the answer here: Where is the ignore pattern written?

There is only one “global” .stignore file per configured folder root. Files with that name in sub-directories are not considered at all.

They’re however not “global” in view of several devices, i.e. you have to set the patterns on each device separately. They do not need to be identical, but that’s the most useful way in many scenarios. To ease maintenance, you can include .stignore-shared (however you want that named) on each device and then edit the patterns in that synchronized file.

1 Like

Thank you for your response. When you say

Did you really mean to say

#include .stignore-shared

And following on from that are you saying that a ‘.stignore’ file can have an arbitrary name provided the file name always starts with .stignore?

Also following on from that if I wanted to use .stignore-shared does that mean that I don’t in that scenario have to include at all a .stignore file in the root of the partition/folder I want to sync? Or would I have to have both a .stignore file and a .stignore-shared file?

Sorry if my questions don’t make a lot sense. I’m kind of struggling with the concepts here.

Yes, that missing # was a typo, sorry.

Syncthing reads only one file, it must be named .stignore at the folder root. However, you can include arbitrary files from there, whatever they are named and in whatever subdirectory of the folder they live.

So, no to both your follow-up questions. You do need both files if you want to have synchronized ignore patterns.

1 Like

So to try and check if I am getting what you are saying right:

I have a desktop and a laptop computer.

If I want to sync them then I need a .stignore file in the root directory of whatever is being synced on both the desktop and the laptop. Do those files have to be identical?

For both of those .stignore files, the one in the desktop and the one in the laptop, I can put a line like #include .stignore.software and that file will be synced on both the desktop and the laptop?

This means that on the desktop or laptop I can make edits to any one of the two .stignore.software files and (a) those ‘filter’ changes will be synced to the device in which I didn’t edit the file and (b) those changes will then be used on both the desktop and laptop to filter files because an #include .stignore.software is referenced in the root .stignore file.

So, in the round, the adding of an arbitrarily named .stignore.[whatevername] file adds filters to the syncing which might not be present in the (root) .stignore file? Is that correct? So doing all this is a way of having for your own use a .stignore file that will contain filters you would always want use and your arbitrarily named files just contain other filters specific to the actual directory you are syncing?

Have I now got this concept right? Or is there a flaw in my thinking?

If my thinking is right then I would have the question, how swiftly would an edit to one of the .stignore.software files be propagated to the other computer and when would the edit ‘filter actions’ in the file be used by ST? Would it, for example on the editing of one of the arbitrarily named files, be necessary for me to press the ‘Rescan’ button to bring the new filters into effect?

You don’t NEED an .stignore file at all. If you want to use it, it deos NOT need to be identical on both machines. However, having different ignore patterns can lead to awkward situations and is really only useful if you want partial sync on one device and / or there are more than two devices involved.

Yes. It the included file will be synced just like any other regular file within the folder.

Yes.

It’s not only creating such a file, but the #include directive which makes Syncthing respect those patterns. And the name is completely arbitrary, it could also be LastUnicorn-common-patterns-for-Syncthing.txt or whatever. You just use that file name in the #include line in the one and only .stignore file (per device).

I’m not quite sure you’ve completely got to the right understanding yet. The .stignore file can be present in any shared folder root, on any device. They are completely independent and only used on that device, for that folder. They are not synced, so they can apply individual ignore patterns that are needed only on that device. Further, you can include any other file into that .stignore, as long as it exists underneath the same folder root, using a relative path. Whether such an included file is synced to other devices depends on whether you have an active ignore pattern for that file itself or not. So including a non-ignored file with patterns is the way to have synchronized ignore patterns between devices.

I’m a bit fuzzy on the details, but I think the .stignore file and any included files are automatically watched for changes and will be re-read before other files when scanning for changes. If you have disabled the filesystem watcher for a specific folder, it might take until the next periodic scan before the new patterns are picked up, but they should always apply during that same scan already.

Please note that the ignore patterns apply not only to the locally present files, but also to changes received from a remote device. Thus not re-reading them in time could lead to some remote changes being applied first, before the resulting files are then ignored locally, but left untouched aftwerwards.

Make sure you’ve read Ignoring Files — Syncthing documentation thoroughly, it should answer most of your questions.

1 Like