在使用git的时候,应该都有遇到过空目录不能提交到git resp的情况!

在StackOverflow上有这样一个问题

Can I add empty directories?

对此的解答

Currently the design of the Git index (staging area) only permits files to be listed, and nobody competent enough to make the change to allow empty directories has cared enough about this situation to remedy it. Directories are added automatically when adding files inside them. That is, directories never have to be added to the repository, and are not tracked on their own. You can say “git add ” and it will add the files in there. If you really need a directory to exist in checkouts you should create a file in it. .gitignore works well for this purpose (there is also a tool MarkEmptyDirs using the .NET framework which allows you to automate this task); you can leave it empty or fill in the names of files you do not expect to show up in the directory.

大致意思就是不可以,如果真的要添加一个“空目录”,可以采取其他变通的做法。

比方说在这个“空目录”里面添加.gitignore或者.gitkeep等隐藏文件。