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


推荐阅读
  • Go Cobra命令行工具入门教程
    本文介绍了Go语言实现的命令行工具Cobra的基本概念、安装方法和入门实践。Cobra被广泛应用于各种项目中,如Kubernetes、Hugo和Github CLI等。通过使用Cobra,我们可以快速创建命令行工具,适用于写测试脚本和各种服务的Admin CLI。文章还通过一个简单的demo演示了Cobra的使用方法。 ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • 本文详细介绍了git常用命令及其操作方法,包括查看、添加、提交、删除、找回等操作,以及如何重置修改文件、抛弃工作区修改、将工作文件提交到本地暂存区、从版本库中删除文件等。同时还介绍了如何从暂存区恢复到工作文件、恢复最近一次提交过的状态,以及如何合并多个操作等。 ... [详细]
  • 欢乐的票圈重构之旅——RecyclerView的头尾布局增加
    项目重构的Git地址:https:github.comrazerdpFriendCircletreemain-dev项目同步更新的文集:http:www.jianshu.comno ... [详细]
  • 在Docker中,将主机目录挂载到容器中作为volume使用时,常常会遇到文件权限问题。这是因为容器内外的UID不同所导致的。本文介绍了解决这个问题的方法,包括使用gosu和suexec工具以及在Dockerfile中配置volume的权限。通过这些方法,可以避免在使用Docker时出现无写权限的情况。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • Commit1ced2a7433ea8937a1b260ea65d708f32ca7c95eintroduceda+Clonetraitboundtom ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • FeatureRequestIsyourfeaturerequestrelatedtoaproblem?Please ... [详细]
  • Go语言实现堆排序的详细教程
    本文主要介绍了Go语言实现堆排序的详细教程,包括大根堆的定义和完全二叉树的概念。通过图解和算法描述,详细介绍了堆排序的实现过程。堆排序是一种效率很高的排序算法,时间复杂度为O(nlgn)。阅读本文大约需要15分钟。 ... [详细]
  • iOS Swift中如何实现自动登录?
    本文介绍了在iOS Swift中如何实现自动登录的方法,包括使用故事板、SWRevealViewController等技术,以及解决用户注销后重新登录自动跳转到主页的问题。 ... [详细]
  • EzPP 0.2发布,新增YAML布局渲染功能
    EzPP发布了0.2.1版本,新增了YAML布局渲染功能,可以将YAML文件渲染为图片,并且可以复用YAML作为模版,通过传递不同参数生成不同的图片。这个功能可以用于绘制Logo、封面或其他图片,让用户不需要安装或卸载Photoshop。文章还提供了一个入门例子,介绍了使用ezpp的基本渲染方法,以及如何使用canvas、text类元素、自定义字体等。 ... [详细]
  • Android日历提醒软件开源项目分享及使用教程
    本文介绍了一款名为Android日历提醒软件的开源项目,作者分享了该项目的代码和使用教程,并提供了GitHub项目地址。文章详细介绍了该软件的主界面风格、日程信息的分类查看功能,以及添加日程提醒和查看详情的界面。同时,作者还提醒了读者在使用过程中可能遇到的Android6.0权限问题,并提供了解决方法。 ... [详细]
  • [转载]从零开始学习OpenGL ES之四 – 光效
    继续我们的iPhoneOpenGLES之旅,我们将讨论光效。目前,我们没有加入任何光效。幸运的是,OpenGL在没有设置光效的情况下仍然可 ... [详细]
  • 详解 Python 的二元算术运算,为什么说减法只是语法糖?[Python常见问题]
    原题|UnravellingbinaryarithmeticoperationsinPython作者|BrettCannon译者|豌豆花下猫(“Python猫 ... [详细]
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社区 版权所有