You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Git子模块安装异常:执行init/update无响应问题排查

私有GitHub子模块执行init/update无反应问题排查

问题概况

在仓库中添加GitHub私有仓库作为子模块后,执行git submodule init和git submodule update --init --recursive无任何输出,子模块目录也未生成文件。已配置SSH别名和部署密钥,但问题依旧。

现有配置

SSH配置

Host github.com-id_rsa_data
  Hostname github.com
  IdentityFile=/home/runner/.ssh/id_rsa_data

初始.gitmodules文件

[submodule "_posts_from_sub/"]
    path = _posts_from_sub/
    url = https://github.com-id_rsa_data/<username-redacted>/test-data

Action执行命令

git submodule init
git submodule update --init --recursive

已尝试的URL格式

  1. 格式一:
[submodule "_posts_from_sub/"]
    path = _posts_from_sub/
    url = git@github.com-id_rsa_data/<username-redacted>/test-data
  1. 格式二:
[submodule "_posts_from_sub/"]
    path = _posts_from_sub/
    url = git@github.com-id_rsa_data:<username-redacted>/test-data
  1. 格式三:
[submodule "_posts_from_sub/"]
    path = _posts_from_sub/
    url = git+ssh://git@github.com-id_rsa_data:<username-redacted>/test-data

排查与解决方案

1. 修正SSH URL格式并验证权限

你的第二种URL格式(git@github.com-id_rsa_data:<username-redacted>/test-data)是正确的,但需确认:

  • 部署密钥已添加到私有子模块仓库的Settings > Deploy keys中,且勾选了对应权限(只读/读写)。
  • 确保Action环境中密钥文件权限为600,可在步骤中添加:
    chmod 600 /home/runner/.ssh/id_rsa_data
    

2. 测试SSH连接有效性

在Action步骤中添加命令验证SSH别名能否正常连接GitHub:

ssh -T git@github.com-id_rsa_data

若输出Hi <username-redacted>! You've successfully authenticated, but GitHub does not provide shell access.说明连接正常,否则需检查SSH配置、密钥或部署密钥。

3. 启用Git调试日志排查细节

Git子模块命令不支持--verbose,但可通过环境变量或全局配置查看详细日志:

# 方式一:设置环境变量
GIT_TRACE=1 git submodule update --init --recursive

# 方式二:调整Git日志级别
git config --global logLevel debug
git submodule init
git submodule update --init --recursive

通过日志可定位权限错误、URL解析失败等具体问题。

4. 确认子模块已正确注册

执行命令检查子模块是否被Git识别:

git submodule status

若输出为空,说明子模块未正确添加,需重新执行添加命令并提交变更:

git submodule add git@github.com-id_rsa_data:<username-redacted>/test-data _posts_from_sub/
git add .gitmodules _posts_from_sub/
git commit -m "Add test-data submodule"

5. 确保Action环境加载SSH配置

GitHub Action默认可能不会自动加载自定义SSH配置,可在步骤中显式创建并设置权限:

echo -e "Host github.com-id_rsa_data\n  Hostname github.com\n  IdentityFile=/home/runner/.ssh/id_rsa_data" > ~/.ssh/config
chmod 600 ~/.ssh/config

内容的提问来源于stack exchange,提问作者vy218

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 18:15:42