[解决方案] [git报错] fatal: reference is not a tree: xxx 以及 Unable to checkout ‘xxx‘ in submodule path xxx

本文解决了一个在配置sosed工具过程中遇到的git子模块更新错误。错误源于使用了--depth1参数和过旧的git版本(1.9.1)。升级至git 2.28.0后,问题得以解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

本文旨在解决如题所示的问题。(预告:是由--depth 1这个参数和git版本导致的)

场景复现

我要配置的是一个叫sosed的工具。

# 克隆代码
git clone https://github.com/JetBrains-Research/sosed.git

而后我根据其指导配置了conda环境,然后到了 python3 -m sosed.setup_tokenizer 这一步
setup_tokenizer要运行几个指令:

# 把该项目tag为v.1.1.1的版本克隆到tokenizer文件夹
git clone --branch=v1.1.1 https://github.com/JetBrains-Research/identifiers-extractor.git tokenizer
cd tokenizer
# 更新子模块
git submodule update --init --recursive --depth 1
cd ..

在运行到git submodule update --init --recursive --depth 1的时候,就出现了错误:

fatal: reference is not a tree: e213464b5062017dc058cfb7effe2fc7a2eebb04
fatal: reference is not a tree: 6002fcd5e86bb1e8670157bb008b97dbaf656d95
Unable to checkout 'e213464b5062017dc058cfb7effe2fc7a2eebb04' in submodule path 'identifiers_extractor/parsers/vendor/tree-sitter-bash'
Unable to checkout '6002fcd5e86bb1e8670157bb008b97dbaf656d95' in submodule path 'identifiers_extractor/parsers/vendor/tree-sitter-c'

如果读者朋友遇到和我类似的场景,那么以下即为你需要的解决方案。

解决方案

根据 git submodule update --depth 1: reference is not a tree,我发现以上出错的原因是:

  • 1) --depth 1 导致只克隆了最浅的一个commit,那么除非你需要的commit id(比如我们上面的e213464b5062017dc058cfb7effe2fc7a2eebb04和这个最浅的commit id恰好一样,才不会报错)
  • 2)在git版本大于等于2.8的情况下,即使--depth 1 ,也不会报以上错误。

然后我看了下我的git版本,只有git version 1.9.1
随后我按照:Ubuntu之Git更新git version 1.9.1更新到:git version 2.28.0,对应指令如下:

sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git

现在重新运行git submodule update --init --recursive --depth 1,就不会再有问题啦!

(所以还是我Ubuntu 14.04 上的git太老旧了。)

其他参考

不是很重要,但是在最开始的时候也给了我一些启发。

小结

配置一个工具,小麻烦还是很多的。
所以需要不断积累,有种“工匠”精神的感觉。

由于我在autodl租的服务器无法访问gitlab,我已经将eigen拉到了本地,如何使lietorch访问我本地的eigen文件夹,而不访问gitlab,报错如下:(mast3r-slam) root@autodl-container-cc3746a64c-4c1769bd:~/MASt3R-SLAM# pip install --no-build-isolation -e . Looking in indexes: http://mirrors.aliyun.com/pypi/simple Obtaining file:///root/MASt3R-SLAM Checking if build backend supports build_editable ... done Preparing editable metadata (pyproject.toml) ... done Collecting lietorch@ git+https://github.com/princeton-vl/lietorch.git (from MAST3R-SLAM==0.0.1) Cloning https://github.com/princeton-vl/lietorch.git to /tmp/pip-install-f0x_dt_2/lietorch_04351692bdf34ddb927c576984b5b361 Running command git clone --filter=blob:none --quiet https://github.com/princeton-vl/lietorch.git /tmp/pip-install-f0x_dt_2/lietorch_04351692bdf34ddb927c576984b5b361 Resolved https://github.com/princeton-vl/lietorch.git to commit 0fa9ce8ffca86d985eca9e189a99690d6f3d4df6 Running command git submodule update --init --recursive -q fatal: unable to access 'https://gitlab.com/libeigen/eigen.git/': The requested URL returned error: 503 fatal: clone of 'https://gitlab.com/libeigen/eigen.git' into submodule path '/tmp/pip-install-f0x_dt_2/lietorch_04351692bdf34ddb927c576984b5b361/eigen' failed Failed to clone 'eigen'. Retry scheduled fatal: unable to access 'https://gitlab.com/libeigen/eigen.git/': The requested URL returned error: 503 fatal: clone of 'https://gitlab.com/libeigen/eigen.git' into submodule path '/tmp/pip-install-f0x_dt_2/lietorch_04351692bdf34ddb927c576984b5b361/eigen' failed Failed to clone 'eigen' a second time, aborting error: subprocess-exited-with-error × git submodule update --init --recursive -q did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × git submodule update --init --recursive -q did not run successfully. │ exit code: 1 ╰─> See above for output.
03-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值