百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
F

fit-commit

> 开发工具
开源

一个 Git 钩子,可根据社区标准验证您的提交消息。

473 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

一个 Git 钩子,可根据社区标准验证您的提交消息。

Fit Commit

A Git hook to validate your commit messages based on community standards.

Example

…

yaml

Validators/LineLength: Enabled: true MaxLineLength: 72 SubjectWarnLength: 50 AllowLongUrls: true Validators/Tense: Enabled: true Validators/SubjectPeriod: Enabled: true Validators/CapitalizeSubject: Enabled: true WarnOnWiplikes: true Validators/Frathouse: Enabled: true Validators/Wip: Enabled: false


The `Enabled` property accepts multiple formats:

```yaml
# true/false to enable/disable the validation (branch agnostic)
Validators/Foo:
  Enabled: false
# Array of String or Regex matching each branch it's enabled on
Validators/Bar:
  Enabled:
    - main
    - !ruby/regexp /\Afoo.+bar/

Adding Custom Validators

Create your custom validator as a FitCommit::Validators::Base subclass:

ruby
module FitCommit
  module Validators
    class MyCustomValidator < Base
      def validate_line(lineno, text)
        if text =~ /sneak peak/i
          add_error(lineno, "I think you mean 'sneak peek'.")
        end
      end
    end
  end
end

# A validator can also validate the commit message as a whole:
module FitCommit
  module Validators
    class MyCustomValidator < Base
      def validate(lines)
        if lines.none? { |line| line.text =~ /#\d+/ }
          add_warning(lines.last.lineno, "Related issue not referenced.")
        end
      end
    end
  end
end

Require the file and enable the validator in your config:

yaml
FitCommit:
  Require:
    - somedir/my_custom_validator.rb
Validators/MyCustomValidator:
  Enabled: true

You can also publish your validator as a gem, and require it that way:

yaml
FitCommit:
  Require:
    - my-custom-validator-gem
Validators/MyCustomValidator:
  Enabled: true

If others might find your validator useful, submit it as a Pull Request. If it's not useful for everyone, it can be disabled by default.

FAQ

Can Fit Commit run in all my repos without having to install it each time?

First set your global Git template directory:

$ git config --global init.templatedir '~/.git_template'
$ mkdir -p ~/.git_template/hooks

Now you can copy the hooks you want installed in new repos by default:

# From a repo where Fit Commit is already installed
$ cp .git/hooks/commit-msg ~/.git_template/hooks/commit-msg

To copy your default hooks into existing repos:

$ git init

How can I run this standalone, like part of a CI process?

Fit Commit can be run outside of a Git hook context with a simple shell script:

bash
$ export GIT_BRANCH_NAME=branch_name
$ export COMMIT_MESSAGE_PATH=path/to/message
# Using Bundler
$ bundle exec ruby -e 'require "fit_commit"; FitCommit.run'
# Not using Bundler
$ rbenv exec ruby -rrubygems -e 'require "fit_commit"; FitCommit.run'

It exits with an error code if any errors are present, which will fail a build if it's part of a CI run.

Who decided these rules?

Fit Commit aims to enforce community standards. The two influential guides are:

  • Tim Pope's blog
  • The official Git documentation

The Git community has largely (but not completely) coalesced around these standards. Chris Beams and the Pro Git book also provide good summaries on why we have them.

How can I improve Fit Commit?

Fit Commit aims to be useful to everyone. If you can suggest an improvement to make it useful to more people, please open a GitHub Issue or Pull Request. See CONTRIBUTING.md for more info.

Credits

Author: Mike Foley

Inspiration taken from: Tim Pope, Jason Fox, Addam Hardy, pre-commit

Similar projects:

  • gitlint (written in Python)
  • fit-commit-js (Node.js package)

Issues· 3 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubycommit-messagegitgit-addonsgit-hooks

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类开发工具
定价开源

> 相关工具

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具