git 如何使用 .gitignore 忽略文件夹中的所有子文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41264102/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to ignore all subfolders in a folder with .gitignore
提问by Boris Zinchenko
I have a folder in Git with some files in it. Files are a part my Git repository. When running my project some work directories appear in this folder. Directories can have any name and any nesting level with multiple sub-directories. I want to ignore all possible sub-directories appearing in this folder but still keep all files (not directories) sitting in root of my folder.
我在 Git 中有一个文件夹,里面有一些文件。文件是我的 Git 存储库的一部分。运行我的项目时,此文件夹中会出现一些工作目录。目录可以具有任何名称和具有多个子目录的任何嵌套级别。我想忽略出现在此文件夹中的所有可能的子目录,但仍将所有文件(而不是目录)保留在我文件夹的根目录中。
I've tried patterns:
我试过模式:
/
*/
/*
/*/
None of above gives desired result. How it can be accomplished?
以上都没有给出预期的结果。如何实现?
Many answers explain how to ignore folders with specific names, for instance Git ignore sub folders. But there seem no explanation on how to ignore all sub-folders with wild cards.
许多答案解释了如何忽略具有特定名称的文件夹,例如 Git ignore sub folders。但是似乎没有关于如何忽略所有带有通配符的子文件夹的解释。
采纳答案by Tim Biegeleisen
Try this:
尝试这个:
!folder/
folder/*
The first line excludesthe top level from being ignored, and the second line ignores all subfolders.
第一行排除顶层被忽略,第二行忽略所有子文件夹。
回答by kan
It's quite simple. Create the .gitignore
in the folder with:
这很简单。.gitignore
在文件夹中创建:
*/*
I.e. ignore all files which are in any folder of the current folder.
即忽略当前文件夹的任何文件夹中的所有文件。