正确地忽略除特定文件类型之外的特定文件夹下的所有文件 [英] Correctly ignore all files recursively under a specific folder except for a specific file type
问题描述
我看过类似的问题( 1 , 2 和< a href =https://stackoverflow.com/questions/8024924/gitignore-ignore-all-files-then-recursively-allow-foo> 3 ),但我没有得到正确的解决方案他们。
I have seen similar questions (1, 2 and 3), but I don't get a proper solution from them.
我需要忽略除特定文件类型之外的特定文件夹下的所有文件。该文件夹是根路径的子目录。让我命名文件夹 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.
这是我要实现的:
# 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.
推荐答案
a href =https://stackoverflow.com/questions/17812717/correctly-ignore-all-files-recursively-under-a-specific-folder-except-for-a-spec/17821597#comment30450162_17821597> @SimonBuchan是正确的。
@SimonBuchan is correct.
由于git 1.8.2,资源/ **!资源/ ** / *。foo
工作。
Since git 1.8.2, Resources/** !Resources/**/*.foo
works.
这篇关于正确地忽略除特定文件类型之外的特定文件夹下的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!