我的 git 仓库怎么会有一个没有 master ref 的 master?

How can my git repo have a master without a master ref?

我一直在学习 git 内部原理,据我了解,每个分支都应该有一个 ref 文件,文件内容是该分支的尖端提交 sha1。 HEAD 文件的内容同时(通常)指向您当前所在分支的引用。

所以我正在研究我的存储库,我得到了这个...

~/code/git-playground/repo1 $ cat .git/HEAD 
ref: refs/heads/master
~/code/git-playground/repo1 $ find .git -type f | grep master
.git/logs/refs/heads/master
~/code/git-playground/repo1 $ ls .git/refs/heads/
chester-branch

所以我有 HEAD 指向 refs/heads/master,但是那个 ref 文件不存在! /logs 中只有一些内容甚至提到了 master。但我仍然可以切换到那个分支。

~/code/git-playground/repo1 $ git branch
  brad-branch
  chester-branch
* master
~/code/git-playground/repo1 $ git checkout chester-branch
Switched to branch 'chester-branch'
~/code/git-playground/repo1 $ git branch
  brad-branch
* chester-branch
  master

所以这是怎么回事?根据 git 书,我应该在 .git/refs/heads 中看到每个分支的文件,但那里什么也没有!

作为,引用可以打包。打包引用存在于今天表示为平面文件数据库的内容中,每行一个条目,在 .git/packed-refs.

在内部,Git 现在有一个抽象层,其中 refs 可以由任何给定的后端以任何任意方式表示。目前只有两种后端:一种将 refs 存储在文件中,另一种将它们存储在单个 packed-refs 文件中,但我希望 Git 很快就会使用真实的数据库来避免在 Windows 和 MacOS 上出现的问题具有看似随机的区分大小写或不区分大小写的分支名称行为。