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

替换torch-mlir子模块时遇git错误:upload-pack: not our ref

替换torch-mlir子模块的正确方法

你遇到的核心问题是torch-mlir引用的mlir-hlo提交哈希<aHash>在你服务器的仓库中不存在,甚至原GitHub仓库也没有,导致git submodule update无法拉取对应版本。子模块的拉取依赖父仓库指定的具体commit,必须确保你的私有服务器仓库包含该commit,或者修改父仓库的子模块引用为你仓库已有的commit。

场景1:保留torch-mlir原本指定的子模块版本

如果需要继续使用torch-mlir要求的特定commit,先把该commit同步到你服务器的仓库:

  1. 临时获取缺失的commit

    # 进入mlir-hlo子模块目录
    cd externals/mlir-hlo
    # 添加原mlir-hlo仓库作为上游远程(若未添加)
    git remote add upstream https://github.com/tensorflow/mlir-hlo.git
    # 拉取所有上游提交,包括目标<aHash>
    git fetch upstream
    # 切换到缺失的commit
    git checkout <aHash>
    
  2. 将该commit推送到你服务器的仓库

    # 推送到私有服务器,可创建专门分支保留该版本
    git push origin <aHash>:refs/heads/torch-mlir-required
    
  3. 重新配置并更新子模块

    # 返回torch-mlir根目录
    cd ../..
    # 修改.gitmodules中mlir-hlo的URL为你服务器的仓库路径
    # 同步URL配置
    git submodule sync
    # 初始化并更新子模块
    git submodule update --init --recursive
    

场景2:改用你服务器上已存在的子模块版本

如果不需要严格使用torch-mlir指定的版本,可切换为你服务器仓库中已有的commit:

  1. 切换到服务器仓库的目标commit

    cd externals/mlir-hlo
    # 拉取服务器仓库的最新提交
    git pull origin main
    # 切换到你想使用的commit哈希<my-hash>
    git checkout <my-hash>
    cd ../..
    
  2. 更新torch-mlir对子模块的引用

    # 提交子模块版本变更到torch-mlir仓库
    git add externals/mlir-hlo
    git commit -m "Update mlir-hlo submodule to use private server commit <my-hash>"
    
  3. 后续正常更新子模块
    之后执行git submodule update --init --recursive就会拉取你服务器上的指定版本。

关键注意事项

  • 子模块的版本绑定基于具体commit哈希而非分支,父仓库的.gitmodules仅提供拉取地址,必须确保私有仓库包含父仓库指定的commit才能成功拉取。
  • 如果原GitHub仓库也没有<aHash>,说明torch-mlir可能使用了自己fork的mlir-hlo分支,可查看torch-mlir仓库的README或子模块配置,找到对应的mlir-hlo源仓库,拉取对应commit后再推送到你的私有服务器。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 07:35:25