Creating a sparse and shallow clone of a git repository results in error: trying to write non-commit object

Creating a sparse and shallow clone of a git repository results in error: trying to write non-commit object

我想在某个标签处创建 git 存储库的稀疏浅层克隆。

这是我目前正在做的事情:

git init avatica-tmp

cd avatica-tmp

git remote add origin https://github.com/apache/calcite-avatica/

git config core.sparsecheckout true

echo "core/src/main/protobuf/*" >> .git/info/sparse-checkout

git pull --depth=1 origin rel/avatica-1.10.0

它工作正常,但抛出错误:

remote: Counting objects: 531, done.
remote: Compressing objects: 100% (381/381), done.
remote: Total 531 (delta 147), reused 280 (delta 51), pack-reused 0
Receiving objects: 100% (531/531), 963.03 KiB | 233.00 KiB/s, done.
Resolving deltas: 100% (147/147), done.
From https://github.com/apache/calcite-avatica
 * tag               rel/avatica-1.10.0 -> FETCH_HEAD
fatal: update_ref failed for ref 'HEAD': cannot update ref 'refs/heads/master': trying to write non-commit object fe4f0b4ea3e2ee4f3b2e82329363a7945493a8c9 to branch 'refs/heads/master'

我在 Git 2.11.0 Ubuntu 17.04 和 Git 2.13.2.windows.1 在 Windows 10 64 位上收到此错误.我没有尝试克隆到映射驱动器。

是什么原因导致此错误,我该如何避免?

您正在尝试使用空存储库中的浅克隆将带注释的标签拉入当前分支,我想这是问题所在,因为它试图将您的本地 master 分支设置为指向该标签,并且git不喜欢。

一个解决方案是使用 fetch,然后检查获取的标签:

git fetch --depth=1 origin rel/avatica-1.10.0
git checkout FETCH_HEAD