git 子模块更新在一台机器上失败并出现错误,但在另一台机器上可以工作
我创建了一个 git 子模块并将其推送到我们的主存储库中。这工作得很好,我可以通过浏览器看到存储库中的子模块。
为了测试它,我尝试在新的构建树中获取源代码。 首先,我运行 git submodule init ,然后运行 git submodule update
第二个命令失败并出现错误:
error: pathspec 'x/mypkg' did not match any file(s) known to git. Did you forget to 'git add'
我尝试将子模块的 url 添加到 .gitmodules
中,但没有成功。
I created a git submodule and pushed it onto our main repository. This worked fine and I can see the submodule in the repository via a browser.
To test it I tried to get the source in a fresh build tree.
First I ran git submodule init
and then git submodule update <submodule-name>
.
The second command failed with error:
error: pathspec 'x/mypkg' did not match any file(s) known to git. Did you forget to 'git add'
I tried adding to .gitmodules
the url to the submodule but with no luck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在尝试更新不在索引中的子模块时使用 TortoiseGit 也收到了此错误。也就是说,它们存在于
.gitmodules
中,但尚未正确添加到存储库中。解决方案是使用 .gitmodules 中指定的路径手动重新添加它们。您可以使用 TortoiseGit UI 或在每个模块的命令行上运行它...
< em>(我意识到这可能不是原始海报的解决方案,但希望它可以帮助其他人谷歌搜索。)
I also received this error using TortoiseGit while trying to update submodules that aren't in the index. That is, they exist in
.gitmodules
but have not been correctly added to the repository.The solution is to manually re-add them using the paths specified in
.gitmodules
. You can use the TortoiseGit UI or run this on the command line for each module...(I realise this is probably not the solution for the original poster, but hopefully it helps others Googling this.)
这可能是因为您或您团队中的某人在子模块中进行了未发布的更改(已提交,但未推送到远程服务器)。然后,他们发布了超级项目,并引用了 git 服务器上不存在的子模块中的 git 提交。因此 git 正在尝试拉取它找不到的特定子模块 git commit ID。
如果更改位于您计算机上其他位置或另一台计算机上的存储库中,就会出现这种情况。
要解决此问题,请转到引用将子模块更改提交并发布(推送)到服务器的存储库。或者更改子模块以指向不同的提交 ID。
This is likely because you or someone on your team has changes in your submodule that are unpublished (committed, but not pushed to the remote server). They then published the superproject with references to the git commit in the submodule which does not exist on the git server. So git is trying to pull down a specific submodule git commit ID that it can't find.
This would be the case if the changes are in a repository elsewhere on your machine or on another machine.
To resolve, go to that repository that references that commit and publish (push) the submodule changes to the server. Or change the submodule to point to a different commit ID.
为了将新的子模块放入其他存储库,我相信您需要在开始运行 git submodule update 之前运行 git submodule init 一次;这将从
.git/config
中的.gitmodules
注册新的子模块。In order to get new submodules into other repositories, I believe you need to run
git submodule init
once before starting to rungit submodule update
; this will register the new submodule from.gitmodules
in.git/config
.