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

Github Action执行git tag命令报错:malformed object name 'origin/test~1'

问题分析与解决方案

报错原因

  1. 浅克隆导致历史缺失:Github Action生产环境默认可能使用浅克隆(仅拉取最新1次提交),没有获取远程分支origin/test的完整提交历史,因此无法解析origin/test~1这个指向父提交的引用。
  2. fetch命令不完整:仅执行git fetch --tags只会拉取远程标签,不会同步远程分支的引用和完整历史,本地没有建立origin/test的追踪引用,自然无法识别基于它的父提交。

解决步骤

  • 确保完整克隆仓库:如果使用Github Action的actions/checkout动作,添加fetch-depth: 0参数,拉取仓库的完整历史:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0
    
  • 补全fetch操作:在执行git fetch --tags之前或之后,执行完整的远程分支同步命令,确保本地获取origin/test的引用和历史:
    git fetch origin test:refs/remotes/origin/test
    # 或者拉取所有远程分支+标签
    git fetch --all --tags --prune
    
  • 验证远程引用:执行以下命令确认origin/test已存在于本地:
    git show-ref --heads --remotes
    

额外提示

如果生产环境有克隆深度限制,也可以单独拉取origin/test分支的最近2次提交(足够解析~1):

git fetch origin test --depth=2

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 16:32:05