git 会忽略空文件夹吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3030230/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:33:52  来源:igfitidea点击:

Does git ignore empty folders?

gitversion-control

提问by Eno

I created an Android project, added it to my git repo, comitted and pushed my clone to the master. Later I tried checking out the project and Eclipse complained about missing src folders. I checked my repo and the master repo and the src folders are missing (Im sure they were there when I created the project). So can someone explain what happened here? Im new to git so maybe I missed something?

我创建了一个 Android 项目,将它添加到我的 git 存储库中,提交并将我的克隆推送到主服务器。后来我尝试检查项目,Eclipse 抱怨缺少 src 文件夹。我检查了我的 repo 和 master repo 以及 src 文件夹丢失(我确定它们在我创建项目时就在那里)。那么有人可以解释这里发生了什么吗?我是 git 新手,所以也许我错过了什么?

回答by J?rg W Mittag

Git doesn't ignore empty directories. It ignores alldirectories. In Git, directories exist only implicitly, through their contents. Empty directories haveno contents, therefore they don't exist.

Git 不会忽略空目录。它忽略所有目录。在 Git 中,目录仅通过其内容隐式存在。空目录没有内容,因此它们不存在。

Or to put it another way: Git is a content tracker. Empty directories are not content.

或者换句话说:Git 是一个内容跟踪器。空目录不是内容。

回答by Michael Forrest

Yes, git ignores empty folders.

是的,git 忽略空文件夹。

You can add an empty .gitignoreor .gitkeepfile to any folders you want included.

您可以将空文件.gitignore.gitkeep文件添加到要包含的任何文件夹中。

回答by pmr

Git tracks content not files.

Git 跟踪内容而不是文件。

A solution is proposed here.

这里提出一个解决方案。

回答by Dustin

git ignores all directories whether they're empty or not.

git 忽略所有目录,无论它们是否为空。

git will recreate directories when building out a tree on disk when a file needs to exist in a directory that does not. Otherwise, no attention is paid to directories.

当文件需要存在于不存在的目录中时,git 将在磁盘上构建树时重新创建目录。否则,不会关注目录。

回答by Ademir Mazer Jr - Nuno

Yes, git ignores empty folders, some suggestions on how to solve that are:

是的,git 会忽略空文件夹,关于如何解决这个问题的一些建议是:

  1. put a README file inside the folder and describe the folder content or why is the folder empty and must be kept
  2. put an empty file called .gitignore inside the folder
  3. (wich I like most) put an empty file called .gitkeep inside. This solution is contextual since if some one see the file will understand why is it in the folder
  1. 在文件夹中放一个 README 文件并描述文件夹内容或为什么文件夹为空且必须保留
  2. 在文件夹中放置一个名为 .gitignore 的空文件
  3. (我最喜欢)在里面放一个名为 .gitkeep 的空文件。此解决方案是上下文相关的,因为如果有人看到该文件就会明白为什么它在文件夹中

回答by labratmatt

Yes, git will not track empty folders. Find a full discussion here on StackOverflow

是的,git 不会跟踪空文件夹。在此处找到有关 StackOverflow 的完整讨论