简体   繁体   English

在gitignore中包括特定的文件扩展名

[英]Including specific file extension in gitignore

I want to include all the *.meta files in the Assets directory and all subdirectories while excluding everything else in Assets 我想在Assets目录和所有子目录中包含所有* .meta文件,同时排除Assets中的所有其他内容

I tried 我试过了

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

but that only include *.meta within /Assets ???? 但这仅包括/ Assets中的* .meta ????

Thanks for any help 谢谢你的帮助

First, if an ignore rule does not work, you can check this with git check-ignore : 首先,如果忽略规则不起作用,则可以使用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) * :除非git 2.中满足某些条件,否则,请参见下文)

That is why your rules only include *.meta within /Assets (and not the subdirectories) 这就是为什么您的规则仅在/Assets (而不是子目录)中包含*.meta原因

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). 我使用git 2.4.1进行了测试,它可以正常工作(甚至在Windows上)。
It does include only the *.meta files in Assets and all subdirectories, but exclude everything else. 它确实仅在Assets和所有子目录中包含*.meta文件,但排除了其他所有内容。


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 . 请注意,在git 2.9.x / 2.10(2016年中?)下, 如果重新包含的路径中没有通配符,则如果排除了该文件的父目录,则可以重新包含该文件。

Nguyễn Thái Ngọc Duy ( pclouds ) is trying to add this feature: NguyễnTháiNgọcDuy( pclouds试图添加此功能:

However, since one of the condition to re-inclusion was: 但是,由于重新包含的条件之一是:

The directory part in the re-include rules must be literal (ie no wildcards) 重新包含规则中的目录部分必须为原义(即没有通配符)

That would not have worked here. 那在这里是行不通的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM