.gitkeep
.gitkeep是一个占位文件。
Git是不会把一个完全空的文件夹添加到版本控制里,为了让空文件夹被跟踪,常规做法是在空文件夹里添加.gitkeep。
注意:.gitkeep并不是Git的特性。Git没有对占位文件名有要求,你可以放一个README也行。
git - What are the differences between .gitignore and .gitkeep? - Stack Overflow https://stackoverflow.com/questions/7229885/what-are-the-differences-between-gitignore-and-gitkeep
.gitkeep
isn’t documented, because it’s not a feature of Git.
Git cannot add a completely empty directory. People who want to track empty directories in Git have created the convention of putting files called .gitkeep
in these directories. The file could be called anything; Git assigns no special significance to this name.
There is a competing convention of adding a .gitignore
file to the empty directories to get them tracked, but some people see this as confusing since the goal is to keep the empty directories, not ignore them; .gitignore
is also used to list files that should be ignored by Git when looking for untracked files.
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 <dir>
" 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.