我从这篇文章中了解到,如果想让Git跟踪一个文件夹,至少必须有一个空文件:
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.
我遇到了一些问题,因为git无法跟踪空文件夹,以下是其中几个问题: 问题1: 我有一个apache/log目录在我的git仓库中。当我将其推送到服务器并运行网站时,没有工作。在我的本地系统上它很好用。经过大量的研究,我发现git push没有推送空文件夹log。服务器检查文件夹log以创建日志文件。由于文件夹log不存在,因此不可能自动创建一个文件夹并放置这些文件。这就是错误的原因。 问题2: 我有很多分支。只有一个特定的分支frontend有文件夹caps。有时目录my_git_repo/caps/html/home/中的某个文件夹为空。master分支没有caps文件夹。如果我执行git checkout master,他将有一个空文件夹caps/html/home/tmp,所以我想手动删除文件夹caps,有时会造成混淆。
通常我通过在文件夹中放置一个空文件(README)来解决这些问题。
git checkout
命令时,会出现很多空文件夹。这真的很麻烦。 - suhailvsgit
根本不跟踪文件夹,无论它们是否为空。文件夹只是git
跟踪的文件路径名称的附属产物。 - twalberg