我正在尝试使用所有可用的 refs
来镜像本地存储库,包括 refs/notes/*
。但是,笔记并未按预期克隆。
要重现问题,请在空目录中执行以下命令:
$ git init repo && cd repo
$ git commit --allow-empty -m 'initial commit'
$ git notes add -m 'Initial commit on empty repo' HEAD
$ git clone --mirror .git ../mirror
获取 refs 之间的差异表明镜像存储库中缺少 notes
:
$ diff repo/.git/refs mirror/refs
Common subdirectories: repo/.git/refs/heads and mirror/refs/heads
Common subdirectories: repo/.git/refs/tags and mirror/refs/tags
Only in repo/.git/refs: notes
git -C mirror fetch
也不会获取注释,即使在 mirror/中指定了
.fetch = +refs/*:refs/*
配置
现在的问题是:我是否遗漏了什么?我正在使用 git 2.3.0
最佳答案
当 git clone
或 git fetch
获得引用资料后,他们通常会将它们“打包”。
未打包的引用在 .git/refs/
中每个文件存储一个。根据他们的全名,得到.git/refs/heads/master
和 .git/refs/notes/commits
例如。
压缩引用(当前)全部存储在一个文件中,.git/packed-refs
.这包含每行一个引用,以及一些引用的额外“剥离”变体(实际上是带注释的标签)。
如果一个引用同时出现在两个地方,Git “更喜欢”未打包的那个(这样它就不必在更新引用时从打包文件中删除条目)。更新引用通常会解压它:继续更新像 .git/refs/heads/master
这样的单条目文件会更好和/或更容易。而不是继续替换多条目文件中的一行。
Git 允许随时解包或重新打包引用,所以很简单 diff
两个.git
树不能保证对你有任何好处。 (这同样适用于打包和解包的对象,但我看到你只是在区分 refs
子目录。)所以你引用的 diff 输出没有说明笔记是否被克隆.要查看笔记是否被克隆,请进入克隆并使用读取笔记的操作。
无论如何,如果有fetch = +refs/*:refs/*
行,您应该复制笔记。
关于Git 注释在 `git clone --mirror` 之后丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45918232/