Git忽略子目录以外的目录中的所有内容 [英] Git Ignore everything in a directory except subfolders
本文介绍了Git忽略子目录以外的目录中的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的文件夹结构:
This is my folder structure:
data/
.gitignore
uploads/
.gitignore
我想提交这些文件夹,但不提供其中的文件。
I would like to commit the folders but not the files inside them.
因此,我在每个包含以下内容的文件夹中添加一个.gitignore文件:
So I add a .gitignore files in every folder with the following content:
# Ignore everything in this directory
*
# Except this file
!.gitignore
问题在于 *
也与目录匹配,所以git只跟踪 data / .gitignore
The problem is that *
matches also on directories so git tracks only data/.gitignore
推荐答案
解决方案非常简单,在.gitignore中添加!* /
文件和当前文件夹中的文件将被忽略
The solution is quite easy, add !*/
to the .gitignore files and only files in the current folder will be ignored
# Ignore everything in this directory
*
# Except this file
!.gitignore
# Except folders
!*/
这篇关于Git忽略子目录以外的目录中的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文