Search code examples
gitmacosfilesystemscross-platformgitignore

Can I safely gitignore "._" prefixed files


I'm working on a Unity project which is being developed on both windows and mac OS. I'm getting these annoying "._" prefixed files in the repo, when I commit from the mac os side, can I safely ignore these files (like one can with DS_STOREs)?


Solution

  • Yes, it's generally safe to ignore those files, especially when working cross-platform. They can contain a variety of Mac-specific filesystem metadata; your Windows computers wouldn't know what to do with that metadata anyway, so if you were depending on it for some reason... you'd be out of luck on the Windows side whether or not they're retained.

    In more detail: macOS's preferred volume formats, HFS+ and APFS, can store a wide variety of metadata about files -- Finder info, tags, quarantine status, whatever. Most of this is stored as "Extended Attributes" or xattrs, which you can see from the macOS command line with ls -l@ or xattr -l. But other volume formats (and archive formats like tar and zip) don't support all this extended metadata, so the Mac filesystem stores it in a separate file with a "._" prefix, in "AppleDouble" format.

    Most of this additional information isn't really needed (or sometimes even meaningful) for transfer between different macOS system, and none of it is meaningful to a Windows system. So it's generally safe to leave it out when transferring files.

    (For an example where it's not safe to lose the metadata, see this Q&A. It involved a Finder alias file -- kind of like a symlimk, but different -- that lost the metadata that identifies it as an alias, and became unusable as a result. But Windows doesn't understand Finder aliases anyway, so you'd better not be using them in your project.)

    BTW, you'll sometimes see these files referred to as containing "resource forks", but that's not really correct. Resource forks are an older type of Mac-specific metadata, which is hardly used anymore. If you do have any files with resource forks, and put them on a non-Mac-native volume, the resource forks would be stored in the "._" files (along with any other xattrs), but you probably don't, so it's unlikely the "._" files even contain resource forks at all.