热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Git子模块头#39;引用不是树#39;错误

本文翻译自:GitsubmoduleheadreferenceisnotatreeerrorIhaveaprojectwithasubmodulethatispoin

本文翻译自:Git submodule head 'reference is not a tree' error

I have a project with a submodule that is pointing to an invalid commit: the submodule commit remained local and when I try to fetch it from another repo I get: 我有一个带有子模块的项目,该子模块指向无效的提交:子模块提交仍然是本地的,当我尝试从另一个repo获取它时,我得到:

$ git submodule update
fatal: reference is not a tree: 2d7cfbd09fc96c04c4c41148d44ed7778add6b43
Unable to checkout '2d7cfbd09fc96c04c4c41148d44ed7778add6b43' in submodule path 'mysubmodule'

I know what the submodule HEAD should be, is there any way I can change this locally, without pushing from the repo that does have commit 2d7cfbd09fc96c04c4c41148d44ed7778add6b43 ? 我知道子模块HEAD应该是什么,有什么办法,我可以在当地改变这一状况,在不脱离确实有承诺回购推2d7cfbd09fc96c04c4c41148d44ed7778add6b43 ?

I'm not sure if I'm being clear... here's a similar situation I found. 我不确定我是否清楚...... 这是我发现的类似情况 。




#1楼

参考:https://stackoom.com/question/92qN/Git子模块头-引用不是树-错误




#2楼

Your submodule history is safely preserved in the submodule git anyway. 无论如何,您的子模块历史记录都安全地保存在子模块git中。

So, why not just delete the submodule and add it again? 那么,为什么不删除子模块并重新添加呢?

Otherwise, did you try manually editing the HEAD or the refs/master/head within the submodule .git 否则,您是否尝试在子模块.git手动编辑HEADrefs/master/head




#3楼

Assuming the submodule's repository does contain a commit you want to use (unlike the commit that is referenced from current state of the super-project), there are two ways to do it. 假设子模块的存储库确实包含您要使用的提交(与从超级项目的当前状态引用的提交不同),有两种方法可以执行此操作。

The first requires you to already know the commit from the submodule that you want to use. 第一个要求您已经知道要使用的子模块的提交。 It works from the “inside, out” by directly adjusting the submodule then updating the super-project. 它通过直接调整子模块然后更新超级项目从“内部,外部”工作。 The second works from the “outside, in” by finding the super-project's commit that modified the submodule and then reseting the super-project's index to refer to a different submodule commit. 第二个工作来自“外部,中”,通过查找超级项目的修改子模块的提交,然后重新设置超级项目的索引以引用不同的子模块提交。


Inside, Out 反了

If you already know which commit you want the submodule to use, cd to the submodule, check out the commit you want, then git add and git commit it back in the super-project. 如果你已经知道你希望子模块使用哪个提交,请cd到子模块,检查你想要的提交,然后git addgit commitgit commit回超级项目。

Example: 例:

$ git submodule update
fatal: reference is not a tree: e47c0a16d5909d8cb3db47c81896b8b885ae1556
Unable to checkout 'e47c0a16d5909d8cb3db47c81896b8b885ae1556' in submodule path 'sub'

Oops, someone made a super-project commit that refers to an unpublished commit in the submodule sub . 哎呀,有人做了一个超级项目提交,它引用了子模块sub未发布的提交。 Somehow, we already know that we want the submodule to be at commit 5d5a3ee314476701a20f2c6ec4a53f88d651df6c . 不知何故,我们已经知道我们希望子模块处于提交5d5a3ee314476701a20f2c6ec4a53f88d651df6c Go there and check it out directly. 去那里直接看看。


Checkout in the Submodule 子模块中的结帐

$ cd sub
$ git checkout 5d5a3ee314476701a20f2c6ec4a53f88d651df6c
Note: moving to '5d5a3ee314476701a20f2c6ec4a53f88d651df6c' which isn't a local branch
If you want to create a new branch from this checkout, you may do so
(now or later) by using -b with the checkout command again. Example:git checkout -b
HEAD is now at 5d5a3ee... quux
$ cd ..

Since we are checking out a commit, this produces a detached HEAD in the submodule. 由于我们正在检查提交,因此在子模块中生成一个分离的HEAD。 If you want to make sure that the submodule is using a branch, then use git checkout -b newbranch to create and checkout a branch at the commit or checkout the branch that you want (eg one with the desired commit at the tip). 如果你想确保子模块正在使用一个分支,那么使用git checkout -b newbranch git checkout -b newbranch 时创建并签出一个分支,或者检查你想要的分支(例如,在提示处有所需提交的分支) )。


Update the Super-project 更新超级项目

A checkout in the submodule is reflected in the super-project as a change to the working tree. 子模块中的结账在超级项目中反映为对工作树的更改。 So we need to stage the change in the super-project's index and verify the results. 因此,我们需要在超级项目的索引中进行更改并验证结果。

$ git add sub

Check the Results 检查结果

$ git submodule update
$ git diff
$ git diff --cached
diff --git c/sub i/sub
index e47c0a1..5d5a3ee 160000
--- c/sub
+++ i/sub
@@ -1 +1 @@
-Subproject commit e47c0a16d5909d8cb3db47c81896b8b885ae1556
+Subproject commit 5d5a3ee314476701a20f2c6ec4a53f88d651df6c

The submodule update was silent because the submodule is already at the specified commit. 子模块更新是静默的,因为子模块已经在指定的提交中。 The first diff shows that the index and worktree are the same. 第一个差异显示索引和工作树是相同的。 The third diff shows that the only staged change is moving the sub submodule to a different commit. 第三个差异表明,唯一的分阶段变化是将sub子模块移动到另一个提交。


Commit 承诺

git commit

This commits the fixed-up submodule entry. 这将提交修复后的子模块条目。




Outside, In 外面,在

If you are not sure which commit you should use from the submodule, you can look at the history in the superproject to guide you. 如果您不确定应该从子模块中使用哪个提交,则可以查看超级项目中的历史记录以指导您。 You can also manage the reset directly from the super-project. 您还可以直接从超级项目管理重置。

$ git submodule update
fatal: reference is not a tree: e47c0a16d5909d8cb3db47c81896b8b885ae1556
Unable to checkout 'e47c0a16d5909d8cb3db47c81896b8b885ae1556' in submodule path 'sub'

This is the same situation as above. 这与上述情况相同。 But this time we will focus on fixing it from the super-project instead of dipping into the submodule. 但这一次我们将重点从超级项目中修复它,而不是浸入子模块中。


Find the Super-project's Errant Commit 找到超级项目的错误提交

$ git log --oneline -p -- sub
ce5d37c local change in sub
diff --git a/sub b/sub
index 5d5a3ee..e47c0a1 160000
--- a/sub
+++ b/sub
@@ -1 +1 @@
-Subproject commit 5d5a3ee314476701a20f2c6ec4a53f88d651df6c
+Subproject commit e47c0a16d5909d8cb3db47c81896b8b885ae1556
bca4663 added sub
diff --git a/sub b/sub
new file mode 160000
index 0000000..5d5a3ee
--- /dev/null
+++ b/sub
@@ -0,0 +1 @@
+Subproject commit 5d5a3ee314476701a20f2c6ec4a53f88d651df6c

OK, it looks like it went bad in ce5d37c , so we will restore the submodule from its parent ( ce5d37c~ ). 好吧,看起来它在ce5d37cce5d37c ,所以我们将从它的父节点恢复子模块( ce5d37c~ )。

Alternatively, you can take the submodule's commit from the patch text ( 5d5a3ee314476701a20f2c6ec4a53f88d651df6c ) and use the above “inside, out” process instead. 或者,您可以从补丁文本( 5d5a3ee314476701a20f2c6ec4a53f88d651df6c )中获取子模块的提交,并使用上面的“内部,外部”过程。


Checkout in the Super-project 超级项目结账

$ git checkout ce5d37c~ -- sub

This reset the submodule entry for sub to what it was at commit ce5d37c~ in the super-project. 这将sub的子模块条目重置为超级项目中commit ce5d37c~的内容。


Update the Submodule 更新子模块

$ git submodule update
Submodule path 'sub': checked out '5d5a3ee314476701a20f2c6ec4a53f88d651df6c'

The submodule update went OK (it indicates a detached HEAD). 子模块更新正常(它表示已分离的HEAD)。


Check the Results 检查结果

$ git diff ce5d37c~ -- sub
$ git diff
$ git diff --cached
diff --git c/sub i/sub
index e47c0a1..5d5a3ee 160000
--- c/sub
+++ i/sub
@@ -1 +1 @@
-Subproject commit e47c0a16d5909d8cb3db47c81896b8b885ae1556
+Subproject commit 5d5a3ee314476701a20f2c6ec4a53f88d651df6c

The first diff shows that sub is now the same in ce5d37c~ . 第一个差异显示sub现在在ce5d37c~是相同的。 The second diff shows that the index and worktree are the same. 第二个差异显示索引和工作树是相同的。 The third diff shows the only staged change is moving the sub submodule to a different commit. 第三个差异显示唯一的分阶段变化是将sub子模块移动到另一个提交。


Commit 承诺

git commit

This commits the fixed-up submodule entry. 这将提交修复后的子模块条目。




#4楼

Just to be sure, try updating your git binaries. 只是为了确定,尝试更新你的git二进制文件。

GitHub for Windows has the version git version 1.8.4.msysgit.0 which in my case was the problem. GitHub for Windows有版本git version 1.8.4.msysgit.0 ,在我的例子中是问题。 Updating solved it. 更新解决了它。




#5楼


Possible cause 可能的原因

This can happens when: 这可能发生在:


  1. Submodule(s) have been edited in place 子模块已经过编辑
  2. Submodule(s) committed, which updates the hash of the submodule being pointed to 提交的子模块 , 它更新被指向的子模块的哈希值
  3. Submodule(s) not pushed . 子模块未被推动

eg something like this happened: 例如这样的事情发生了:

$ cd submodule
$ emacs my_source_file # edit some file(s)
$ git commit -am "Making some changes but will forget to push!"

Should have submodule pushed at this point. 此时应该有子模块。

$ cd .. # back to parent repository
$ git commit -am "updates to parent repository"
$ git push origin master

As a result, the missing commits could not possibly be found by the remote user because they are still on the local disk. 因此,远程用户无法找到丢失的提交,因为它们仍在本地磁盘上。


Solution

Informa the person who modified the submodule to push, ie 将修改子模块的人告知,即

$ cd submodule
$ git push



#6楼

I got this error when I did: 我做的时候遇到了这个错误:

$ git submodule update --init --depth 1

but the commit in the parent project was pointing at an earlier commit. 但是父项目中的提交指向了先前的提交。

Deleting the submodule folder and running: 删除子模块文件夹并运行:

$ git submodule update --init

did NOT solve the problem. 没有解决问题。 I deleted the repo and tried again without the depth flag and it worked. 我删除了回购并再次尝试没有深度标志,它工作。

This error happens in Ubuntu 16.04 git 2.7.4, but not on Ubuntu 18.04 git 2.17, TODO find exact fixing commit or version. 这个错误发生在Ubuntu 16.04 git 2.7.4中,但在Ubuntu 18.04 git 2.17上没有,TODO找到了确切的修复提交或版本。


推荐阅读
  • 版本控制工具——Git常用操作(下)
    本文由云+社区发表作者:工程师小熊摘要:上一集我们一起入门学习了git的基本概念和git常用的操作,包括提交和同步代码、使用分支、出现代码冲突的解决办法、紧急保存现场和恢复 ... [详细]
  • 尽管使用TensorFlow和PyTorch等成熟框架可以显著降低实现递归神经网络(RNN)的门槛,但对于初学者来说,理解其底层原理至关重要。本文将引导您使用NumPy从头构建一个用于自然语言处理(NLP)的RNN模型。 ... [详细]
  • 本文详细介绍了如何在Linux系统上安装和配置Smokeping,以实现对网络链路质量的实时监控。通过详细的步骤和必要的依赖包安装,确保用户能够顺利完成部署并优化其网络性能监控。 ... [详细]
  • 本文介绍了如何使用JQuery实现省市二级联动和表单验证。首先,通过change事件监听用户选择的省份,并动态加载对应的城市列表。其次,详细讲解了使用Validation插件进行表单验证的方法,包括内置规则、自定义规则及实时验证功能。 ... [详细]
  • 扫描线三巨头 hdu1928hdu 1255  hdu 1542 [POJ 1151]
    学习链接:http:blog.csdn.netlwt36articledetails48908031学习扫描线主要学习的是一种扫描的思想,后期可以求解很 ... [详细]
  • 在现代网络环境中,两台计算机之间的文件传输需求日益增长。传统的FTP和SSH方式虽然有效,但其配置复杂、步骤繁琐,难以满足快速且安全的传输需求。本文将介绍一种基于Go语言开发的新一代文件传输工具——Croc,它不仅简化了操作流程,还提供了强大的加密和跨平台支持。 ... [详细]
  • 网络运维工程师负责确保企业IT基础设施的稳定运行,保障业务连续性和数据安全。他们需要具备多种技能,包括搭建和维护网络环境、监控系统性能、处理突发事件等。本文将探讨网络运维工程师的职业前景及其平均薪酬水平。 ... [详细]
  • 毕业设计:基于机器学习与深度学习的垃圾邮件(短信)分类算法实现
    本文详细介绍了如何使用机器学习和深度学习技术对垃圾邮件和短信进行分类。内容涵盖从数据集介绍、预处理、特征提取到模型训练与评估的完整流程,并提供了具体的代码示例和实验结果。 ... [详细]
  • 本文探讨了高质量C/C++编程的最佳实践,并详细分析了常见的内存错误及其解决方案。通过深入理解内存管理和故障排除技巧,开发者可以编写更健壮的程序。 ... [详细]
  • 本文介绍了如何使用JavaScript的Fetch API与Express服务器进行交互,涵盖了GET、POST、PUT和DELETE请求的实现,并展示了如何处理JSON响应。 ... [详细]
  • 如何配置Unturned服务器及其消息设置
    本文详细介绍了Unturned服务器的配置方法和消息设置技巧,帮助用户了解并优化服务器管理。同时,提供了关于云服务资源操作记录、远程登录设置以及文件传输的相关补充信息。 ... [详细]
  • 本文探讨了如何在编程中正确处理包含空数组的 JSON 对象,提供了详细的代码示例和解决方案。 ... [详细]
  • 本文详细介绍了Python中函数的基本概念,包括函数的定义与调用、文档注释、参数传递(形参与实参)、返回值以及函数嵌套。通过具体示例和解释,帮助读者掌握函数在编程中的应用。 ... [详细]
  • 利用Selenium与ChromeDriver实现豆瓣网页全屏截图
    本文介绍了一种使用Selenium和ChromeDriver结合Python代码,轻松实现对豆瓣网站进行完整页面截图的方法。该方法不仅简单易行,而且解决了新版Selenium不再支持PhantomJS的问题。 ... [详细]
  • 在尝试从数据库获取设置的过程中,遇到了一个致命错误:Fatal error: Call to a member function bind_param() on boolean。本文将详细分析该错误的原因,并提供解决方案。 ... [详细]
author-avatar
大市低开_127
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有