Could not resolve hostname xxx.com: Name or service not known

在构建项目时遇到Couldnotresolvehostnamexxx.com:Nameorservicenotknown的SSH错误,这通常是由于子模块的远程URL与.gitmodules中的不一致导致。使用gitsubmodulesync--recursive可以更新所有子模块的URL配置,确保与上游同步,从而解决此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Could not resolve hostname xxx.com: Name or service not known

今天构建项目时,报错,感觉是更新子仓代码的问题,试了 git submodule initgit submodule update 还是报一样的错:

ssh: Could not resolve hostname xxx.com: Name or service not known
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 'xxx'
exit status 12023-03-06 10:22:02        FATAL   cmd/main.go:65  exit status 1

问大佬,扔给我一个 git submodule sync --recursive

git官方文档的解释是

sync [--recursive] [--] [<path>…​]
Synchronizes submodules' remote URL configuration setting to the value specified in .gitmodules. It will only affect those submodules which already have a URL entry in .git/config (that is the case when they are initialized or freshly added). This is useful when submodule URLs change upstream and you need to update your local repositories accordingly.

git submodule sync synchronizes all submodules while git submodule sync -- A synchronizes submodule "A" only.

If --recursive is specified, this command will recurse into the registered submodules, and sync any nested submodules within.

大致意思就是

sync 子模块的远程URL配置设置为.gitmodules中指定的值。它只会影响那些在 .git/config 中已经有URL条目的子模块(当它们被初始化或新添加时就是这样)。当子模块 url 在上游发生变化,需要相应地更新本地存储库时,这是非常有用的。

git子模块sync同步所有子模块,而git子模块sync – A 则指定了模块,所以只同步子模块“A”。

如果指定了 --recursive,该命令将递归到已注册的子模块中,并同步其中的任何嵌套子模块。

问题出现的原因就是:

在你拉取的提交中, 可能 .gitmodules 文件中记录的子模块的 URL 发生了改变。

所以通过 git submodule sync --recursive 进行更新即可

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值