# 2021-01-05 #「Git」- 保留空目录

问题描述

在我们项目中,存在数据目录,在程序运行之前,这些目录为空目录。当提交到 Git 仓库时,这些空目录会被忽略。

但是,我们希望保存这些空目录,以体现项目目录结构。

该笔记将整理:在 git 中,如何保留空目录。

解决方案

在空目录中创建 .gitignore 文件,并填入如下内容:

# Ignore everything in this directory
*
# Except this file
!.gitignore

或者,在空目录中创建 .placeholder 文件,在根目录的 .gitignore 填入如下内容:

# Ignore everything in this directory
data/*
# Except this file
!.placeholder

参考文献

K4NZ/保留空目录
How can I add an empty directory to a Git repository? - Stack Overflow


posted @ 2021-01-05 17:05  研究林纳斯写的  阅读(110)  评论(0编辑  收藏  举报