社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Git

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

dale丶无双 • 3 年前 • 1864 次点击  

前言

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

场景复现

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

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

而后我根据其指导配置了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 ..
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

在运行到 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'
  • 1
  • 2
  • 3
  • 4

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

解决方案

根据 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
  • 1
  • 2
  • 3

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

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

其他参考

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

小结

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

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/72019
 
1864 次点击