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

Github Action中Commitizen执行失败:'git-lfs'不在路径,如何解决?

解决GitHub Action中Commitizen Action的Git LFS缺失错误

问题场景

配置了如下GitHub Action,通过Commitizen Action自动完成版本升级和变更日志生成,其中cz步骤开启了lfs: true选项:

name: Python application

on:
  push:
    branches: [ "master" ]

permissions:
  contents: read

jobs:
  bump_version:
    if: "!startsWith(github.event.head_commit.message, 'bump:')"
    runs-on: ubuntu-latest
    name: "Bump version and create changelog with commitizen"
    steps:
      - name: Check out
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
          token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"
      - id: cz
        name: Create bump and changelog
        uses: commitizen-tools/commitizen-action@master
        with:
          github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          lfs: true
      - name: Print Version
        run: echo "Bumped to version ${{ steps.cz.outputs.version }}"

执行时出现以下错误:

Current branch master is up to date.

This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/pre-push'.

error: failed to push some refs to

解决方案

错误原因是ubuntu-latest默认的GitHub Runner环境未预装Git LFS,需在Commitizen Action执行前手动安装并初始化Git LFS:

修改后的完整配置

name: Python application

on:
  push:
    branches: [ "master" ]

permissions:
  contents: read

jobs:
  bump_version:
    if: "!startsWith(github.event.head_commit.message, 'bump:')"
    runs-on: ubuntu-latest
    name: "Bump version and create changelog with commitizen"
    steps:
      - name: Check out
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
          token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"
      - name: Install Git LFS
        run: |
          sudo apt-get update
          sudo apt-get install -y git-lfs
          git lfs install
      - id: cz
        name: Create bump and changelog
        uses: commitizen-tools/commitizen-action@master
        with:
          github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          lfs: true
      - name: Print Version
        run: echo "Bumped to version ${{ steps.cz.outputs.version }}"

关键说明

  • 在Check out步骤之后、cz步骤之前添加Git LFS的安装命令,确保runner环境中存在git-lfs可执行文件
  • git lfs install会初始化Git LFS的钩子配置,避免后续提交时触发钩子校验失败

内容的提问来源于stack exchange,提问作者Tlaloc-ES

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 01:45:32