正确递归地忽略特定文件夹下的所有文件,特定文件类型除外 [英] Correctly ignore all files recursively under a specific folder except for a specific file type

查看:25
本文介绍了正确递归地忽略特定文件夹下的所有文件,特定文件类型除外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过类似的问题(123),但我没有从他们.

I have seen similar questions (1, 2 and 3), but I don't get a proper solution from them.

我需要忽略特定文件夹下的所有文件,特定文件类型除外.该文件夹是根路径的子目录.让我将文件夹命名为 Resources.由于我不想把事情复杂化,让我忽略所有名为 Resources 的文件夹下的文件.

I need to ignore all files under a particular folder except for a specific file type. The folder is a subdirectory for the root path. Let me name the folder Resources. Since I don't want to complicate things, let me ignore files under all folders named Resources wherever it is.

这是最常见的解决方案(在所有重复问题中)

This is the most common solution (in all the duplicate questions)

# Ignore everything
*

# Don't ignore directories, so we can recurse into them
!*/

# Don't ignore .gitignore
!.gitignore

# Now exclude our type
!*.foo

此解决方案的问题在于它停止跟踪新添加的文件(因为 * 忽略所有文件).我不想继续排除每种文件类型.我想要正常的行为,如果添加了任何新文件,git status 会显示它.

The problem with this solution is that it stops tracking newly added files (since * ignores all files). I don't want to keep excluding each and every file type. I want normal behaviour where if any new file is added, git status shows it.

我终于找到了解决方案这里.解决方案是在 Resources 文件夹中添加另一个 .gitignore 文件.这工作正常.

I finally got a solution here. The solution is to add another .gitignore file in Resources folder. This works correctly.

我可以用一个忽略文件来达到同样的效果吗?我发现在不同目录中有许多忽略文件有点笨拙.

Can I achieve the same with one ignore file? I find having many ignore files in different directories a bit clunky.

这就是我想要实现的目标:

This is what I'm trying to achieve:

# Ignore everything under Resources folder, not elsewhere
Resources

# Don't ignore directories, so we can recurse into them
!*Resources/

# Now exclude our type
!*.foo

但这给出了相反的输出.它忽略 *.foo 类型并跟踪其他文件.

But this gives the opposite output. It ignores *.foo types and tracks other files.

推荐答案

@SimonBuchan 是正确的.

从 git 1.8.2 开始,Resources/** !Resources/**/*.foo 有效.

Since git 1.8.2, Resources/** !Resources/**/*.foo works.

这篇关于正确递归地忽略特定文件夹下的所有文件,特定文件类型除外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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