@evilmartians/lefthook-installer

中文文档
2.2.2发布于 2026/10/13MITCommonJS零依赖近 30 天下载 3206

Simple git hooks manager

原始使用文档
文档目录17 节
  1. Install
  2. Usage
  3. Why Lefthook
  4. Parallel execution
  5. Flexible list of files
  6. Glob and regexp filters
  7. Execute in sub-directory
  8. Run scripts
  9. Tags
  10. Support Docker
  11. Local config
  12. Direct control
  13. Your own tasks
  14. Control output
  15. Guides
  16. Examples
  17. Articles

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

Evil Martians logo 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

版本与发布记录

@evilmartians/lefthook-installer 共发布 185 个版本,首次发布于 2022/06/08;过去 12 个月发布了 31 个版本。

版本发布日期距今
2.2.2latest2026/10/131 个月前
2.2.12026/10/081 个月前
2.2.02026/10/081 个月前
2.1.172026/10/051 个月前
2.1.162026/10/021 个月前
2.1.152026/09/301 个月前

关于 @evilmartians/lefthook-installer 的常见问题

@evilmartians/lefthook-installer 是什么?

Simple git hooks manager

如何安装 @evilmartians/lefthook-installer?

在项目目录运行 npm install @evilmartians/lefthook-installer,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 lefthook,可以用 npx lefthook 直接运行。

@evilmartians/lefthook-installer 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/evilmartians__lefthook-installer 是否存在。

@evilmartians/lefthook-installer 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@evilmartians/lefthook-installer 可以商用吗?

@evilmartians/lefthook-installer 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@evilmartians/lefthook-installer 的下载量有多少?

根据 npm 官方下载统计,@evilmartians/lefthook-installer 在 2026/10/14 – 2026/11/12 这 30 天内被下载 3,206 次,日均约 107 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@evilmartians/lefthook-installer 还在维护吗?

最新版本 2.2.2 发布于 2026/10/13(1 个月前);至今共发布 185 个版本,其中过去 12 个月发布了 31 个;首次发布于 2022/06/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。