如何向 .gitignore 中深度嵌套的文件添加异常? [英] How to add an exception to a deeply nested file in .gitignore?
问题描述
我们试图忽略一个文件夹,并向该文件夹内的特定文件添加一个例外,该文件夹内嵌套了几层深.
We are trying to ignore a folder and add an exception to a specific file, within that folder, which is nested several levels deep.
这是我现在的做法(有效,但很复杂):
/ignored_folder/*
!/ignored_folder/foo/
/ignored_folder/foo/*
!/ignored_folder/foo/exception_file.txt
有没有办法简化这个,这对任何深度都有效?此配置不会使 exception_file.txt
成为忽略异常(不起作用):
Is there a way to simplify this, that would work for any depth? This configuration does not make exception_file.txt
an ignore exception (does not work):
/ignored_folder/*
!/ignored_folder/foo/exception_file.txt
推荐答案
忽略文件夹意味着根本不查看它们的内部,并且 ignored_folder/*
匹配(现在误导性命名)中的文件夹名称忽略_文件夹.你想要
Ignoring folders means not looking inside them at all, and ignored_folder/*
matches folder names inside the (now-misleadingly-named) ignored_folder. You want
ignored_folder/**
!ignored_folder/**/
那是递归地忽略ignored_folder
中的所有文件,但不要跳过嵌套文件夹,无论如何都要查看它们,因为我可能想挑选个人里面的文件".
That's "recursively ignore all files inside ignored_folder
, but don't skip over nested folders, look in side them anyway because I might want to cherry-pick individual files inside them".
然后就可以随便加了
!ignored_folder/foo/exception_file.txt
但 tttt 我会从 @TheIceBar 的方法开始,忽略或压制任何警告.
edit: but tttt I'd start with @TheIceBar's method and ignore or squelch any warnings.
这篇关于如何向 .gitignore 中深度嵌套的文件添加异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!