git submodule update 致命错误:引用不是树

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13425298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:56:15  来源:igfitidea点击:

git submodule update fatal error: reference is not a tree

gitversion-control

提问by bouncingHippo

user$ sudo git submodule update
fatal: reference is not a tree: a094dcfeeb43fcd62a9e466156e05e7581026f33
Unable to checkout 'a094dcfeeb43fcd62a9e466156e05e7581026f33' in submodule path 'client/src/util'

What do I do? I just want to get a clean copy of the latest code from the repo, i dont mind losing my changes.As you can tell, I clearly am not sure what is happening. I can only think that it is trying to checkout a file which means git detected a local change in a file on my local machine.

我该怎么办?我只想从 repo 中获得最新代码的干净副本,我不介意丢失我的更改。如您所知,我显然不确定发生了什么。我只能认为它正在尝试检出一个文件,这意味着 git 检测到我本地机器上文件的本地更改。

i am currently using OSX

我目前正在使用 OSX

回答by Adam Dymitruk

This is the most common problem with submodules. The commit that you are on in the outer repository has a reference to a commit in the submodule that someone did not push up yet. It's a dependency problem. Always push from the inside-out. This is most likely not something you did wrong, but someone else that's working in the repository. They were sloppy and forgot to issue push on the submodule and just pushed the containing repository. Stuff works on their machine because they made the change and those commits exist there. Go slap them and tell them to push up their submodule changes :)

这是子模块最常见的问题。您在外部存储库中进行的提交引用了子模块中某人尚未推送的提交。这是一个依赖问题。始终由内而外推动。这很可能不是您做错了什么,而是在存储库中工作的其他人。他们很草率,忘记在子模块上发出推送,只是推送了包含的存储库。东西在他们的机器上运行是因为他们进行了更改并且这些提交存在于那里。去拍打他们并告诉他们推动他们的子模块更改:)

Otherwise, it could be your fault if you were working on another machine and you forgot to push the submodule changes. Now you're at the other location and are thinking "WTF! These are my changes and they should work here too!"

否则,如果您在另一台机器上工作并且忘记推送子模块更改,则可能是您的错。现在您在另一个位置并在想“WTF!这些是我的更改,它们也应该在这里工作!”

回答by Michael Chinen

Most times it will be the case described by Adam Dymitruk, but another case that can cause this is when switching branches that have submodules that changed remotes. This is because the submodule update just tries to do a checkout of the commit, but it won't be able to before adding and fetching the new remote.

大多数情况下,这是 Adam Dymitruk 所描述的情况,但另一种可能导致这种情况的情况是切换具有更改遥控器的子模块的分支时。这是因为子模块更新只是尝试对提交进行检出,但在添加和获取新远程之前它无法完成。

You can verify this by looking at the .gitmodules file and comparing the submodules' URL with the one shown by cd'ing to the submodule and doing a git remote -v

您可以通过查看 .gitmodules 文件并将子模块的 URL 与 cd'ing 到子模块显示的 URL 进行比较并执行以下操作来验证这一点 git remote -v

In this case you will need to run git submodule syncto notify the submodule about the remote change, followed by git submodule update --init --recursiveto get rid of this error.

在这种情况下,您需要运行git submodule sync以通知子模块有关远程更改的信息,然后git submodule update --init --recursive消除此错误。

回答by kenorb

The error means that specific commit (its sha1) is not reachable from any of the refs while cloning your submodule, so you should either update your submodule with valid reference or reset the changes to the latest version.

该错误意味着在克隆子模块时无法从任何引用访问特定提交(其 sha1),因此您应该使用有效引用更新子模块或将更改重置为最新版本。

This may happen when you've new commits in your fork, local or you've included references to your detached HEAD, but you haven't push them into your main repository to which submodule git URL points to.

当您在 fork、本地或您已经包含对分离的 HEAD 的引用时,可能会发生这种情况,但您还没有将它们推送到子模块 git URL 指向的主存储库中。

To reset submodule manually to origin/master, enter subdir of submodule and do the reset, e.g.

要将子模块手动重置为 origin/master,请输入子模块的 subdir 并进行重置,例如

cd client/src/util
git reset origin/master --hard

If you'd like to correct the reference in the main repo, after doing above commit the changes:

如果您想更正主存储库中的引用,请在执行上述操作后提交更改:

# Still in submodule dir.
git pull origin master # In submodule dir.
git push origin master
cd - # Go back to the main repo dir.
git status
git commit -am 'Update submodule refs'
git push


If you'd like to pull and push the references from fork to origin, you can try:

如果您想将引用从 fork 拉入并推送到原点,您可以尝试:

cd client/src/util # Go to submodule dir again.
git remote add fork [email protected]:example/foo.git
git pull fork master
git show a094dcfeeb43fcd62a9e466156e05e7581026f33 # Check previously missing sha1. 
git push origin master:master # Or: master:some_branch

回答by Edward Ned Harvey

In addition to Adam Dymitruk's and Michael Chinen's answers, I encountered this problem due to Windows maximum path length. If I try to clone a particular repo that has 3-level deep submodules, in my Documents/Visual Studio 2013/Projectsdirectory, then I get fatal: reference is not a tree. But if I repeat the same exact clone in my home directory, it works fine.

除了 Adam Dymitruk 和 Michael Chinen 的答案之外,由于 Windows 最大路径长度,我遇到了这个问题。如果我尝试在我的Documents/Visual Studio 2013/Projects目录中克隆一个具有 3 级深度子模块的特定存储库,那么我会得到fatal: reference is not a tree. 但是如果我在我的主目录中重复相同的精确克隆,它工作正常。

回答by Michael Krelin - hacker

Most likely your submodule repository has no revision that is referenced outer repository. And it may also be either not available at the remote specified for submodule, or you do not have remote set up for submodule. You can try to go into client/src/utiland git fetchin there.

很可能您的子模块存储库没有引用外部存储库的修订版。它也可能在为子模块指定的远程不可用,或者您没有为子模块设置远程。你可以尝试进入client/src/util,并git fetch在那里。

(why do you sudoit? if it belongs to root why aren't you not in root shell and if it doesn't, why do you change to root?)

(你为什么这样做sudo?如果它属于 root 为什么你不在 root shell 中,如果不是,你为什么要改为 root?)