gitbare中怎么会没有工作目录呢?

How can there be no working directory in git bare?

我正在阅读这篇文章 here 并且不明白当您 git init --bare 时为什么没有工作目录。怎么可能没有工作目录呢?那不是你所有文件所在的目录吗?当你在你的仓库中创建一个文件时,它不会启动一个工作目录吗?

第二条我也不明白,就是:

There is no .git directory created. Instead, the files normally in the .git directory are placed in the top-level directory where the working directory would normally be.

没有 .git 目录的目的是什么?这如何导致作者关于非裸回购的创建者做 git status 并看到

的例子

git would find a different object database and give different results for this run of git status.

裸存储库和非裸存储库之间的区别 Git 具有误导性,可能会使新手感到困惑。

How can there be no working directory? Isn't that the directory where all your files reside?

没有。实际上,所有信息(即构成 git 存储库的所有数据)都存储在项目根目录中的 .git/ 文件夹中(假设它是一个非裸存储库),即 allGit自己需要创建一个工作目录

工作目录不包含关于存储库的任何状态(例如分支、标签、提交)并且从技术上讲不是它的一部分(即它不是必需的)。它只是程序员编辑文件的一种方式。

这可能有助于理解当您从 Github 上的存储库进行常规克隆时,驻留在 Github 服务器上的存储库是一个裸存储库,但是您get 是一个非裸存储库。

现在回答你的第二个问题。

What is the purpose of not having a .git directory?

想一想:git服务器中工作目录的用途是什么?存储在服务器中的存储库不需要工作目录,因为没有人将通过 SSH 连接到 git 服务器并直接编辑那里的文件。

因此,通过保留 必要的内容(即 .git/ 目录的内容)来简化存储库结构。此外,.git/ 目录的内容放在项目的根文件夹中,因为将它们保存在 .git/ 中没有多大意义,因为根目录中没有其他文件。