热门标签 | 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找到了确切的修复提交或版本。


推荐阅读
  • 线段树详解与实现
    本文详细介绍了线段树的基本概念及其在编程竞赛中的应用,并提供了一个具体的线段树实现代码示例。 ... [详细]
  • 本文详细介绍了Elasticsearch中的分页查询机制,包括基本的分页查询流程、'from-size'浅分页与'scroll'深分页的区别及应用场景,以及两者在性能上的对比。 ... [详细]
  • 题目编号:2049 [SDOI2008]Cave Exploration。题目描述了一种动态图操作场景,涉及三种基本操作:断开两个节点间的连接(destroy(a,b))、建立两个节点间的连接(connect(a,b))以及查询两节点是否连通(query(a,b))。所有操作均确保图中无环存在。 ... [详细]
  • PHP函数的工作原理与性能分析
    在编程语言中,函数是最基本的组成单元。本文将探讨PHP函数的特点、调用机制以及性能表现,并通过实际测试给出优化建议。 ... [详细]
  • 开发笔记:树的浅析与实现 ... [详细]
  • 在尝试加载支持推送通知的iOS应用程序的Ad Hoc构建时,遇到了‘no valid aps-environment entitlement found for application’的错误提示。本文将探讨此错误的原因及多种可能的解决方案。 ... [详细]
  • 在1995年,Simon Plouffe 发现了一种特殊的求和方法来表示某些常数。两年后,Bailey 和 Borwein 在他们的论文中发表了这一发现,这种方法被命名为 Bailey-Borwein-Plouffe (BBP) 公式。该问题要求计算圆周率 π 的第 n 个十六进制数字。 ... [详细]
  • 本问题涉及在给定的无向图中寻找一个至少包含三个节点的环,该环上的节点不重复,并且环上所有边的长度之和最小。目标是找到并输出这个最小环的具体方案。 ... [详细]
  • 洛谷 P4009 汽车加油行驶问题 解析
    探讨了经典算法题目——汽车加油行驶问题,通过网络流和费用流的视角,深入解析了该问题的解决方案。本文将详细阐述如何利用最短路径算法解决这一问题,并提供详细的代码实现。 ... [详细]
  • Irish budget airline Ryanair announced plans to significantly increase its route network from Frankfurt Airport, marking a direct challenge to Lufthansa, Germany's leading carrier. ... [详细]
  • 如何将955万数据表的17秒SQL查询优化至300毫秒
    本文详细介绍了通过优化SQL查询策略,成功将一张包含955万条记录的财务流水表的查询时间从17秒缩短至300毫秒的方法。文章不仅提供了具体的SQL优化技巧,还深入探讨了背后的数据库原理。 ... [详细]
  • 本教程介绍如何在C#中通过递归方法将具有父子关系的列表转换为树形结构。我们将详细探讨如何处理字符串类型的键值,并提供一个实用的示例。 ... [详细]
  • 协程作为一种并发设计模式,能有效简化Android平台上的异步代码处理。自Kotlin 1.3版本引入协程以来,这一特性基于其他语言的成熟理念,为开发者提供了新的工具,以增强应用的响应性和效率。 ... [详细]
  • 本文详细介绍了HashSet类,它是Set接口的一个实现,底层使用哈希表(实际上是HashMap实例)。HashSet不保证元素的迭代顺序,并且是非线程安全的。 ... [详细]
  • android开发分享荐                                                         Android思维导图布局:效果展示及使用方法
    思维导图布局的前身是树形布局,对树形布局基本使用还不太了解的朋友可以先看看我写的树形布局系列教程,了解了树形布局的使用方法后再来阅读本文章。先睹为快来看看效果吧,横向效果如下:纵向 ... [详细]
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社区 版权所有