Git子模块对其远程存储库的引用有误 [英] Git Submodule has a wrong reference to its remote repository

查看:51
本文介绍了Git子模块对其远程存储库的引用有误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主存储库中有两个子模块,两个子模块都链接到另外两个远程存储库.

I have two submodules in my main repository, both linked to two another remote repositories.

  • 当我进入第一个子模块时,我收到一条消息"HEAD detached at xxxxxxxx",这很好,因为远程存储库和子模块具有相同的ID(32位数字). /li>
  • 当我进入第二个子模块时,我收到一条消息与HEAD脱离 yyyyyyyy"-很好,导致远程存储库和子模块执行没有具有相同的ID(32位数字).因此,第二个子模块具有与其链接到的存储库不同的ID.
  • When I enter the 1st submodule I am getting a message "HEAD detached at xxxxxxxx" - which is fine, cause the remote repository and the submodule have the same ID (the 32 digits).
  • When I enter the 2nd submodule I am getting a message "HEAD detached from yyyyyyyy" - which is not fine, cause the remote repository and the submodule do not have the same ID (the 32 digits). So, the 2nd submodule has a different ID than the repository it is linked to.

我认为我设法以某种方式将我的第二个子模块放在其他分支或类似的东西上.
长话短说,我什至无法克隆主要代表(git clone --recursive-submodules),因为第二个子模块具有错误的ID,并且无法链接到其远程代表.
我收到"error: no ref to the remote rep".

I think I somehow manage to put my 2nd submodule on some other branch or something like that.
Long story short, I cannot even clone the main rep anymore (git clone --recursive-submodules) cause the 2nd submodule has a wrong ID and cannot get linked to its remote rep.
I am getting "error: no ref to the remote rep".

有人可以帮我吗?
如何更改子模块的ID?
还是我需要在主分支上找回我的第二个子模块?

Can someone help me?
How can I change the ID of a submodule?
Or do I need to get back my 2nd submodule on the main branch?

推荐答案

如何更改子模块的ID?

How can I change the ID of a submodule?

对于您而言,您无法克隆子模块存储库,因为其 gitlink ,( 父存储库索引中的特殊条目)引用了 not 推送到所述子模块的远程回购.

In your case, you cannot clone your submodule repo, because its gitlink, (special entry in the index of the parent repo) references a SHA1 that was not pushed to the remote repo of said submodule.

由于您没有子模块文件夹的内容(无法检出),因此不能简单地从该子模块添加,推送和提交.

Since you don't have the submodule folder content (it cannot be checked-out), you cannot simply add, push and commit from said submodule.

为了完成克隆,最好将关联的gitlink SHA1更改为其先前版本:

In order to complete the clone, it is best to change the associated gitlink SHA1 to its previous version:

git checkout $(git log -1 --format=format:%H yoursubmodule) -- yoursubmodule

用表示子模块的文件夹名称替换yoursubmodule,不要在末尾加斜杠(因为它是索引中的条目,而不是文件夹)

Replace yoursubmodule by the name of the folder representing your submodule, without trailing slash (since it is an entry in the index, not a folder)

然后 git submodule update --init应该足以初始化该子模块内容.

Then a git submodule update --init should be enough to initialize that submodule content.

最后,请参阅" Git子模块:指定分支/标记",然后将您的子模块与分支关联:

Finally, see "Git submodules: Specify a branch/tag", and associate your submodule to a branch:

git config -f .gitmodules submodule.<path>.branch <branch>

这样,下一次git submodule update --remote将足以将您的子模块更新为该分支的最新远程SHA1.

That way, next time, a git submodule update --remote will be enough to update your submodule to the latest remote SHA1 of that branch.

这篇关于Git子模块对其远程存储库的引用有误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆