在gitignore中包括特定的文件扩展名 [英] Including specific file extension in gitignore

查看:69
本文介绍了在gitignore中包括特定的文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Assets目录和所有子目录中包含所有* .meta文件,同时排除Assets中的所有其他内容

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

我尝试过

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

但是在/Assets中仅包含* .meta吗????

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

感谢您的帮助

推荐答案

首先,如果忽略规则不起作用,则可以检查此使用git check-ignore :

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:

如果排除了该文件的父目录,则无法重新包含该文件. (*)
(*:除非在git 2中满足某些条件?? +,请参见下文)

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)

这就是为什么您的规则仅在/Assets(而不是子目录)中包括*.meta的原因

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

我使用git 2.4.1对其进行了测试,并且可以正常运行(即使在Windows上也是如此).
它确实仅包括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.

请注意,使用git 2.9.x/2.10(2016年中吗?),如果排除了该文件的父目录,则可能可以重新包含该文件

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ễnTháiNgọcDuy(pclouds)试图添加此功能:

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

  • commit 506d8f1 for git v2.7.0, reverted in commit 76b620d git v2.8.0-rc0
  • commit 5e57f9c git v2.8.0-rc0,... reverted(!) in commit 5cee3493 git 2.8.0-rc4.

但是,由于重新纳入的条件之一是:

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)

那在这里是行不通的.

这篇关于在gitignore中包括特定的文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆