本文翻译自: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 <new_branch_name>
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 <commit> 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 <commit>git checkout -b newbranch <commit>时创建并签出一个分支,或者检查你想要的分支(例如,在提示处有所需提交的分支) )。

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子模块头#39;引用不是树#39;错误相关推荐

  1. 什么是未定义的引用/未解决的外部符号错误,如何解决?

    本文翻译自:What is an undefined reference/unresolved external symbol error and how do I fix it? What are ...

  2. 关于python字符编码以下选项中描述错误的是_关于import引用,以下选项中描述错误的是...

    [单选题]11.自动化分析仪中采用同步分析原理的是:() [单选题]以下选项中,不是Python语言合法命名的是 [单选题]下列选项中可以获取Python整数类型帮助的是 [单选题]下面代码的输出结果 ...

  3. win10 vs2017 引用 “windows.h” 报很多错误

    win10 vs2017 引用 "windows.h" 报很多错误: imm.h(339): note: 参见"LRESULT"的声明 winuser.h(85 ...

  4. (2110,5): warning MSB3245: 未能解析此引用。未能找到程序集“Windows”。请检查磁盘上是否存在该程序集。 如果您的代码需要此引用,则可能出现编译错误。

    最近打UE4的包的时候,总是失败.没办法只能各种搜索找答案解决,用了度娘.sougou.bing都没有找到理想的答案,最后没办法翻墙用google找答案,还好最后完美解决了. 下面是编译VS的erro ...

  5. 完整学习git三 查看暂存区目录树 git diff

    1显示暂存区中的目录树 git ls-files git ls-tree git diff 魔法 1工作区与暂存区比较 git diff 2工作区与HEAD比较 git diff HEAD 3暂存区与 ...

  6. 在一个.net sln中包含多个project,project引用同一个dll导致的错误

    在一个.net sln中包含多个project,其中四个project应用了同一个.net assamply:Lucene.Net.这四个project其中一个编译异常:  ForumsDataSou ...

  7. git pull代码出现refusing to merge unrelated histories错误

    本地推送代码到远程出现refusing to merge unrelated histories 本地仓库在想做同步远程仓库到本地为之后本地仓库推送到远程仓库做准备时报错了,错误如下: fatal: ...

  8. git commit时出现unable to auto-detect email address错误

    我的小站.Github 问题描述: 在git commit的时候出现如下报错 *** Please tell me who you are. Run git config --global user. ...

  9. Git本地分支版本过低导致的push错误 error: failed to push some refs to ... 及后续amend

    今天在用git的时候遇到了一个问题.在想远程分支push的时候,出现了下面的错误: ! [remote rejected] master -> refs/for/master (change 1 ...

最新文章

  1. 最短Hamilton路径-状压dp解法
  2. boost::mp11::mp_map_update_q相关用法的测试程序
  3. [原]iBatis.Net(C#)系列一:简介及运行环境
  4. ABB (2020牛客国庆集训派对day1)
  5. 审计利用计算机,利用计算机审计手段 提高审计工作水平
  6. SLAM GMapping(8)重采样
  7. Java中使用BigDecimal进行浮点数精确计算 超大整数 浮点数等计算 没有数位限制
  8. 在 Visual Studio .NET 中使用 SQL Server 2000 创建数据库应用程序(1)
  9. 取消endnotes参考文献格式域的步骤_大学体悟-毕业论文格式篇
  10. Html5 h5页面输入框失去焦点页面底部白板问题
  11. const 与 readonle 的异同
  12. tensorflow 的版本差异与变化
  13. 一个关于传奇3G游戏的感言
  14. 查看dll是32还是64
  15. WMI的讲解(是什么,做什么,为什么)
  16. Python3网络爬虫
  17. RabbitMQ实现即时通讯-MQTT协议
  18. java坦克大战(2.0)
  19. Disc在线端口扫描服务uz! version 5.0.0 suffers from a cross site sc
  20. 进入TP-Link路由器之后利用快捷键F12查看星号路由密码的方法

热门文章

  1. Go 自动构建工具 dogo 代码已托管到 Git@OSC
  2. Incorrect string value: '\xE8\x8B\x8F\xE6\x99\xA8...' for column 'user_name' at row 1
  3. 多校3 1008 Solve this interesting problem
  4. RS报表从按月图表追溯到按日报表
  5. 如何将散乱的css代码规范化、格式化
  6. Laravel-事件简单使用
  7. Python 基础总结
  8. 局网满猿关不住,一波码农出墙来。
  9. Windows核心编程(笔记13) 第十六章--第二十六章
  10. SQLServer扩展存储过程