简体   繁体   English

git submodule update --init 给出错误致命:需要单个修订版无法在子模块路径中找到当前修订版

[英]git submodule update --init gives error fatal: Needed a single revision Unable to find current revision in submodule path

When i execute git submodule update --init I get error当我执行git submodule update --init我得到错误

fatal: Needed a single revision Unable to find current revision in submodule path 'plugins/pluginname'.致命:需要单个修订版无法在子模块路径“插件/插件名”中找到当前修订版。

Actually I was trying to run a Jenkins Job to deploy it.实际上,我正在尝试运行 Jenkins Job 来部署它。 I added Recursively update submodules as additional behavior in Jenkins.我在 Jenkins 中添加了递归更新子模块作为附加行为。 FATAL: Command "git.exe submodule update --init --recursive" returned status code -1: This is occurring only from my local as same command is working for others.致命:命令“git.exe submodule update --init --recursive”返回状态码-1:这仅在我的本地发生,因为相同的命令对其他人有效。

尝试git submodule foreach git pull

It's an example of a hidden actual error in Git, a UX pitfall typical to Git.这是 Git 中隐藏的实际错误的一个示例,这是 Git 的典型 UX 陷阱。

In my case the real error was that I was using a submodule pinned to a branch that doesn't exist anymore (eg feature branch that was already merged and deleted via Gitlab).在我的情况下,真正的错误是我使用了一个固定到不再存在的分支的子模块(例如,已经通过 Gitlab 合并和删除的功能分支)。 Verify if that's the case for you as well and if it is, point the submodule to a new branch.验证您是否也是这种情况,如果是,请将子模块指向一个新分支。

I tried many other suggestions that didn't work, but the commands that worked for me are:我尝试了许多其他不起作用的建议,但对我有用的命令是:

git submodule sync
git submodule update --init

For people falling into this problem with Jenkins I actually found the solution here .对于遇到 Jenkins 这个问题的人,我实际上在这里找到了解决方案。 You can select你可以选择

Wipe out repository & force clone清除存储库并强制克隆

This works but leads to longer checkout这有效,但会导致结账时间更长

For TeamCity users.对于 TeamCity 用户。

Open your VCS Root Settings and change submodules mode from checkout to ignore.打开您的 VCS 根设置并将子模块模式从结帐更改为忽略。 Then you can finally checkout submodules manually in your scripts without this error.然后,您最终可以在脚本中手动检出子模块而不会出现此错误。

An older question, but here's what worked for me.一个较老的问题,但这对我有用。

The error happens because the fetch command the git submodule update runs isn't finding the branch.发生错误是因为git submodule update运行的 fetch 命令没有找到分支。 In my case, I could sync and update all I wanted but it still didn't fix it.就我而言,我可以同步和更新我想要的所有内容,但它仍然没有修复它。 I eventually found my solution in a related answer , but I'm adding here for anyone else runs into it.我最终在相关答案中找到了我的解决方案,但我在这里添加了其他任何遇到它的人。

If the parent repo was shallowly cloned, then remote.origin.fetch in the submodule is restricted to the branch set in the .gitmodule (or the default branch).如果父 repo 被浅层克隆,则子模块中的remote.origin.fetch被限制在.gitmodule中设置的分支(或默认分支)。 In my case, I was only running into the problem with Gitlab CI when I was trying to run tests from the parent repo on a branch of the submodule.就我而言,我只是在尝试从子模块的一个分支上的父仓库运行测试时才遇到 Gitlab CI 的问题。 Submodules worked fine if .gitmodules is modified as part of a commit, but not if changing branch on the runner itself.如果.gitmodules作为提交的一部分进行修改,则子模块可以正常工作,但如果更改运行器本身的分支则不会。

If you're running into this error you can check/fix your submodules with:如果您遇到此错误,您可以检查/修复您的子模块:

git submodule foreach git config --get remote.origin.fetch
# Entering 'good_submodule'
# +refs/heads/*:refs/remotes/origin/*
# Entering 'bad_submodule'
# +refs/heads/someBranch:refs/remotes/origin/someBranch

And you can similarly correct it:你也可以类似地纠正它:

# selectively fix
git -C bad_submodule config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
# ensure all submodules can access everything
git submodule foreach git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM