English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Preface
Git is different from svn, it only tracks file changes, not directories. So, an empty directory, if there are no files inside, even if git add this directory, there is no such empty directory when checking out elsewhere.
Only track file changes, do not track directories. This design has a reason. But it will bring some small troubles. Sometimes, it is indeed necessary to keep an empty directory in the code repository. For example, an empty directory needed for testing. Let's see how to solve it.
Actually, there are two situations here:
First, the directory is empty
In this case, you just need to create a .gitkeep file in the directory and set not to ignore .gitkeep in the project's .gitignore
.gitkeep is a conventional filename and does not have any special rules
Second, there are files already existing in the directory
In this case, you need to set !.gitignore first in the root directory, and then create a .gitignore file in the target directory and set it to
* !\.gitignore
Summary
Alright, now you can submit an empty directory in the project. I hope it can be helpful for your learning or work. If you have any questions, you can leave comments for communication.