2

I want to include all the *.meta files in the Assets directory and all subdirectories while excluding everything else in Assets

I tried

/Assets/*
!/Assets/**/*.meta
!*.meta

but that only include *.meta within /Assets ????

Thanks for any help

chiwangc
  • 3,566
  • 16
  • 26
  • 32
OptimisticMonkey
  • 538
  • 4
  • 13

1 Answers1

6

First, if an ignore rule does not work, you can check this with git check-ignore:

git check-ignore -v -- yourFile

It will display which ignore rule ignore a file that you thought should not be ignored.

Then the main rule to remember when it comes to ignore is:

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.?+, see below)

That is why your rules only include *.meta within /Assets (and not the subdirectories)

You would need to include all parent folders of a file (as in this recent example) in order to include a file

/Assets/**/**
! /Assets/**/
!/Assets/**/*.meta

I tested it with git 2.4.1 and it works (even on Windows).
It does include only the *.meta files in Assets and all subdirectories, but exclude everything else.


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, since one of the condition to re-inclusion was:

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

That would not have worked here.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks VonC - The problem is that I don't know the names of all the subfolders in Assets and they change all the time. :-( I would like to include only the *.meta files in Assets and all subdirectories, but exclude everything else – OptimisticMonkey May 22 '15 at 13:37
  • @OptimisticMonkey can you try with `!/Assets/**/` before `!*.meta`. Maybe that would include all subfolders, before including meta files. – VonC May 22 '15 at 13:39
  • `/Assets/* !/Assets/**/**.meta !/Assets/**/ !*.meta` results in all files being included in Assets – OptimisticMonkey May 22 '15 at 13:41
  • @OptimisticMonkey No: `!/Assets/**/` As I said, you need to include the subfolders in order to include files. That is mentioned in my answer: **It is not possible to re-include a file if a parent directory of that file is excluded.** – VonC May 22 '15 at 13:42
  • How do I exclude all the other files except *.meta that are included now? Sorry - just can't seem to figure it out - always includes all files or only *.meta in the first directory – OptimisticMonkey May 22 '15 at 13:44
  • @OptimisticMonkey Try my edited answer: I just tested it and it works: it does include only the `*.meta` files in `Assets` and all subdirectories, but exclude everything else. – VonC May 22 '15 at 13:52
  • Thanks VonC (Sorry it took long to reply - the comment was not showing) I tried the edited /Assets/**/** ! /Assets/**/ !/Assets/**/*.meta and it still doesnt include any .meta in nested subdirectories :-( – OptimisticMonkey May 22 '15 at 15:24
  • @OptimisticMonkey can you do a `git check-ignore -v -- /path/to/a/file.meta`? – VonC May 22 '15 at 15:30
  • @OptimisticMonkey Well done! You can accept the answer then if it works for you. – VonC May 22 '15 at 17:44
  • Thanks VonC Answer Accepted :-) – OptimisticMonkey May 22 '15 at 20:15