Why are these files not ignored by git?

First, you can do a git check-ignore (git 1.8.3.3+) to see what rule is ignoring your file (assuming it wasn’t in the index in the first place)

Second, read “.gitignore exclude folder but include specific subfolder“:

It is not possible to re-include a file if a parent directory of that file is excluded. (*)
(*: unless certain conditions are met in git 2.8+, see below)
Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined.

So the file of xcschemes wouldn’t be un-ignored anyway.
You needed to ignore parent folder per parent folder.
But a better approach is to ignores files only, and then exclude the folder:

xcuserdata/**
!xcuserdata/**/
!xcuserdata/**/xcschemes/**

Remember:

You need to exclude folders from the gitignore rules before being able to exclude files.


Note that with git 2.9.x/2.10 (mid 2016?), it might be possible to re-include a file if a parent directory of that file is excluded if there is no wildcard in the path re-included.

Nguyễn Thái Ngọc Duy (pclouds) is trying to add this feature:

However:

The directory part in the re-include rules must be literal (i.e. no wildcards)

So that wouldn’t have worked here anyway.

Leave a Comment