如何使用.gitignore忽略文件夹中的所有子文件夹 [英] How to ignore all subfolders in a folder with .gitignore

查看:1810
本文介绍了如何使用.gitignore忽略文件夹中的所有子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Git中有一个文件夹,里面有一些文件.文件是我的Git存储库的一部分.运行我的项目时,某些工作目录会出现在此文件夹中.目录可以具有任何名称和具有多个子目录的任何嵌套级别.我想忽略此文件夹中出现的所有可能的子目录,但仍将所有文件(而非目录)保留在我的文件夹的根目录中.

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.

我尝试过模式:

/
*/
/*
/*/

以上均未提供所需结果.如何实现?

None of above gives desired result. How it can be accomplished?

许多答案说明了如何忽略具有特定名称的文件夹,例如 Git忽略子文件夹. 但是似乎没有解释如何忽略所有带有通配符的子文件夹.

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.

推荐答案

尝试一下:

!folder/
folder/*

第一行排除在顶层,而第二行则忽略所有子文件夹.

The first line excludes the top level from being ignored, and the second line ignores all subfolders.

这篇关于如何使用.gitignore忽略文件夹中的所有子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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