首页 > 解决方案 > Git 子模块 - 无法使用适用于 Windows 的 Linux 子系统访问存储库

问题描述

我正在尝试将 Git 子模块添加到不同的存储库。我创建了我想要的存储库,但子模块是由我的顾问创建的。

为方便起见,假设我要添加的子模块是存储库 A,而我要添加的子模块是存储库 B。

几点注意事项:

  1. 我正在使用适用于 Windows 的 Linux 子系统(即 Ubuntu 终端应用程序)。
  2. 我有一个活跃的互联网连接,并且可以通过标准 git 命令(git pull、push、commit 等)访问这两个存储库
  3. 我可以使用指向 A 的符号链接让我的所有代码正常工作。

这是我将 A 添加到 B 以及相应的终端输出所采取的步骤。

In: git submodule add git@gitlab.com:Respository_B

上面的行工作正常,我可以在 .gitmodules 文件中看到正确的信息,这是输出:

[submodule "Repository_B"]       
    path = repository_B
    url = git@gitlab.com:Repsitory_B

现在,我尝试了以下两件事:

In: git submodule init
Out: fatal: No url found for submodule path 'submodule_A' in .gitmodules

和,

In: git submodule update --remote
Out: setsockopt IPV6_TCLASS 8: Operation not permitted: 

我难住了。我尝试在网上搜索解决方案,但空手而归。有想法该怎么解决这个吗?

另外,如果我需要澄清任何事情,请告诉我。

谢谢!


编辑


刚刚读到Windows 子系统存在一些 chmod 问题,所以我尝试了这一行并得到了不同的错误消息。

In:  sudo git submodule update --remote 
Out: git@gitlab.com: Permission denied (publickey). 
     fatal: Could not read from remote repository. 

     Please make sure you have the correct access rights
     and the repository exists.
     Unable to fetch in submodule path 'Repository_A'

这很奇怪,因为我可以使用指向本地克隆的符号链接来访问存储库。

标签: windowsgitgit-submoduleswindows-subsystem-for-linux

解决方案


我正在尝试添加的是存储库 A,而我尝试将其添加到的是存储库 B。

那么命令将是:

cd /path/to/B
git submodule add git@gitlab.com:Respository_A
git commit -m "Add A to B"
git push

关于错误消息,此问题表明:

我们正在使用的解决方法是将以下行放在 ~/.ssh/config 中:

AddressFamily inet

注意:如果您要连接到 IPv4 主机,则使用 AddressFamily inet 效果很好。如果主机仅为 IPv6,则根本无法连接。


推荐阅读