lefthook

evilmartiansMIT活跃维护

用 Go 写的 Git hooks 管理器,能并行执行 pre-commit、pre-push 等钩子,配置简单、速度快,适合各种语言的项目统一管理提交前检查。

Fast and powerful Git hooks manager for any type of projects.

v2.2.2发布于 2026-10-13 09:20 UTC9,019star +6 / 7 天335fork同步于 2026-11-10 17:31 UTC

怎么上手

由 README 提炼,执行前请确认
npm install lefthook --save-dev
lefthook install
硬件要求按 README 说明

README 未说明,仅需能运行 Go 编译的二进制或对应包管理器的环境,无 GPU 要求

有 Docker 镜像
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

用 Go 写的 Git hooks 管理器,跨语言项目都能用,配置一次即可并行跑检查

用 Go 写的 Git hooks 管理器,能并行执行 pre-commit、pre-push 等钩子,配置简单、速度快,适合各种语言的项目统一管理提交前检查。

核心能力

  • 用 Go 编写的单文件无依赖二进制,任意环境可用
  • 支持 parallel 并行执行多个 hook 命令
  • 用 {staged_files}、{all_files} 等占位符灵活传入文件列表
  • 支持 glob 与 exclude 正则过滤文件
  • 用 tags 和 lefthook-local.yml 按人按需跳过或覆盖命令

容易踩的坑

用 Go 安装需 Go >= 1.27;安装后必须执行 lefthook install 才会写入 git hooks;root 路径需带结尾斜杠

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v2.2.2
  1. v2.2.2最新正式版2026-10-13 · 2026-10-13 09:20 UTC

    Changelog

    • 4aeffd72a6e3ea846c2054cffd6294c943fd7fbb fix: cleanup only current stash hash (#1597)
    • db62412c82ddac71cf536e60e50edb2826624870 packaging: add support for android (#1591)
    • e3fa81b1f01881829ef95e37211da7923a4fd6df refactor(filter): simplify mimetype matching (#1596)
  2. v2.2.12026-10-08 · 2026-10-08 10:35 UTC
    查看更新说明

    Changelog

    • 6dd11f61f54595935746f9e0814c16844fc6d31b feat: support php composer (#1583)
    • c702ccf154bb180107ba5f790518c161d9ce111d fix: generate different patch names when in a worktree (#1582)
    • 486fdd317d29f815821ce2450d42e3a49b066eb0 refactor: cache paths in wrapper (#1570)
  3. v2.2.02026-10-07 · 2026-10-07 19:08 UTC
    查看更新说明

    Changelog

    • 46c65b3871dd96c81624f413b24b3d273b41a4e5 deps: October 2026 (#1571)
    • 37f17131b605cf0f64c29252ebfe94610368f769 fix: don't write an install-time lefthook path into AI hook configs (#1544)
    • cc9969c2e2198aafff8accc63ee1aee30e9a2aa4 fix: ignore trailing NUL in --files-from-stdin (#1574)
    • 57fee374b70c18e17ada20e09a336142d6d8899f fix: pass --output path to git diff as a single argument (#1581)
  4. v2.1.172026-10-05 · 2026-10-05 07:47 UTC
    查看更新说明

    Changelog

    • 8d8073d427fac49cc982919f5280b295645d196d fix: diff push files against the merge base with the default branch (#1565)
    • c12bccd193f43a8419038787bd83b12fe3a4470c fix: don't hash submodules when checking fail_on_changes (#1566)
    • 03225efde40226b14459e901707fbd988d62fcc0 refactor: naming of helpers (#1568)
    • 66746ace996c72ac31b3cb4a70af85607568baf4 refactor: working with git (#1564)
  5. v2.1.162026-10-01 · 2026-10-01 17:29 UTC
    查看更新说明

    Changelog

    • 3ee04318fd06d56a70cc9c90dc8385b19918f520 ci: refactor publishing scripts (#1559)
    • 91407e537b2fa36539506963a33e582dca394798 deps: bump mod and text deps to resolve CVEs (#1560)
    • be6f0ae8793533449cb9a07a253fa9a381e82206 fix: preserve unrelated unstaged changes on conflict (#1483)
    • cf4ef1e19baf0581871f69b40914d64c94ff19d7 fix: test staging fixed files with partially staged

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Build Status codecov

    Lefthook

    A Git hooks manager for Node.js, Ruby, Python and many other types of projects.

    • Fast. It is written in Go. Can run commands in parallel.
    • Powerful. It allows to control execution and files you pass to your commands.
    • Simple. It is single dependency-free binary which can work in any environment.

    📖 Introduction post

    Lefthook is built by Evil Martians, an American design and engineering consultancy for developer tools, AI, and cybersecurity startups.

    Install

    With Go (>= 1.27):

    go install github.com/evilmartians/lefthook/[email protected]
    
    • or as a go tool
    go get -tool github.com/evilmartians/lefthook/[email protected]
    

    With NPM:

    npm install lefthook --save-dev
    

    For Ruby:

    gem install lefthook
    

    For Python:

    pipx install lefthook
    

    Installation guide with more ways to install lefthook: apt, brew, winget, and others.

    Usage

    Configure your hooks, install them once and forget about it: rely on the magic underneath.

    TL;DR
    # Configure your hooks
    vim lefthook.yml
    
    # Install them to the git project
    lefthook install
    
    # Enjoy your work with git
    git add -A && git commit -m '...'
    
    More details

    Why Lefthook

    • Parallel execution

    Gives you more speed. docs

    pre-push:
      parallel: true
    
    • Flexible list of files

    If you want your own list. Custom and prebuilt examples.

    pre-commit:
      jobs:
        - name: lint frontend
          run: yarn eslint {staged_files}
    
        - name: lint backend
          run: bundle exec rubocop --force-exclusion -- {all_files}
    
        - name: stylelint frontend
          files: git diff --name-only HEAD @{push}
          run: yarn stylelint {files}
    
    • Glob and regexp filters

    If you want to filter list of files. You could find more glob pattern examples here.

    pre-commit:
      jobs:
        - name: lint backend
          glob: "*.rb" # glob filter
          exclude:
            - "*/application.rb"
            - "*/routes.rb"
          run: bundle exec rubocop --force-exclusion -- {all_files}
    
    • Execute in sub-directory

    If you want to execute the commands in a relative path

    pre-commit:
      jobs:
        - name: lint backend
          root: "api/" # Careful to have only trailing slash
          glob: "*.rb" # glob filter
          run: bundle exec rubocop -- {all_files}
    
    • Run scripts

    If oneline commands are not enough, you can execute files. docs

    commit-msg:
      jobs:
        - script: "template_checker"
          runner: bash
    
    • Tags

    If you want to control a group of commands. docs

    pre-push:
      jobs:
        - name: audit packages
          tags:
            - frontend
            - linters
          run: yarn lint
    
        - name: audit gems
          tags:
            - backend
            - security
          run: bundle audit
    
    • Support Docker

    If you are in the Docker environment. docs

    pre-commit:
      jobs:
        - script: "good_job.js"
          runner: docker run -it --rm <container_id_or_name> {cmd}
    
    • Local config

    If you are a frontend/backend developer and want to skip unnecessary commands or override something in Docker. docs

    # lefthook-local.yml
    pre-push:
      exclude_tags:
        - frontend
      jobs:
        - name: audit packages
          skip: true
    
    • Direct control

    If you want to run hooks group directly.

    $ lefthook run pre-commit
    
    • Your own tasks

    If you want to run specific group of commands directly.

    fixer:
      jobs:
        - run: bundle exec rubocop --force-exclusion --safe-auto-correct -- {staged_files}
        - run: yarn eslint --fix {staged_files}
    
    $ lefthook run fixer
    
    • Control output

    You can control what lefthook prints with output option.

    output:
      - execution
      - failure
    

    Guides

    Examples

    Check examples

    Articles