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

GitLab CI流水线推送提交至其他仓库失败,报错shallow update not allowed

问题原因

报错shallow update not allowed是因为GitLab CI默认采用浅克隆(仅拉取最近50次提交历史),本地仓库没有完整的提交链。远程仓库出于数据完整性考虑,拒绝接收这种不完整的推送请求。

解决方案

1. 拉取完整仓库历史

在流水线配置中添加全局变量,禁用浅克隆以拉取全部提交历史:

variables:
  GIT_DEPTH: 0

或者在before_script中手动补全历史:

git fetch --unshallow

2. 清理冗余配置

脚本中配置了SSH密钥,但实际使用HTTP方式推送,这些SSH相关步骤完全多余,可直接删除,避免混淆。

3. 优化推送逻辑

无需删除原origin远程仓库,直接新增一个远程别名(如deploy)进行推送更稳妥:

# 替换原脚本中rm/add origin的步骤
git remote add deploy http://USERNAME:${USERNAME_password}@ip:3000/USERNAME/first_exe.git
git push -f deploy main
优化后的完整示例
deploy-job:      
  stage: deploy  
  variables:
    GIT_DEPTH: 0  # 拉取完整提交历史
  script:
    - git branch -a    
    - git config --global user.email "${CI_EMAIL}"
    - git config --global user.name "${CI_USERNAME}"
    - git add .  
    - git commit -m "Compiled PDF from $CI_COMMIT_SHORT_SHA [skip ci]" || echo "No changes, nothing to commit!"
    - git remote add deploy http://USERNAME:${USERNAME_password}@ip:3000/USERNAME/first_exe.git
    - git push -f deploy main

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 17:01:21