Skip to content

Ignoring commits

Ignoring commits

You can configure gitlint to ignore specific commits or parts of a commit.

One way to do this, is by adding a gitlint-ignore line to your commit message.

If you have a case where you want to ignore a certain type of commits all-together, you can use gitlint's ignore rules. Here's a few examples:

[ignore-by-title]
# Match commit titles starting with "Release"
regex=^Release(.*)
ignore=title-max-length,body-min-length # (1)

[ignore-by-body]
# Match commits message bodies that have a line that contains 'release'
regex=(.*)release(.*)
ignore=all

[ignore-by-author-name]
# Match commits by author name (e.g. ignore dependabot commits)
regex=dependabot
ignore=all
  1. Ignore all rules by setting ignore to 'all'.
    [ignore-by-title]
    regex=^Release(.*)
    ignore=all
    

If you just want to ignore certain lines in a commit but still lint the other ones, you can do that using the ignore-body-lines rule.

# Ignore all lines that start with 'Co-Authored-By'
[ignore-body-lines]
regex=^Co-Authored-By

Warning

When ignoring specific lines, gitlint will no longer be aware of them while applying other rules. This can sometimes be confusing for end-users, especially as line numbers of violations will typically no longer match line numbers in the original commit message. Make sure to educate your users accordingly.

Tip

If you want to implement more complex ignore rules according to your own logic, you can do so using user-defined configuration rules.

Merge, fixup, squash and revert commits

v0.7.0 (merge) · v0.9.0 (fixup, squash) · v0.13.0 (revert) · v0.18.0 (fixup=amend)

Gitlint ignores merge, revert, fixup, and squash commits by default.

For merge and revert commits, the rationale for ignoring them is that most users keep git's default messages for these commits (i.e Merge/Revert "[original commit message]"). Often times these commit messages are also auto-generated through tools like github. These default/auto-generated commit messages tend to cause gitlint violations. For example, a common case is that "Merge:" being auto-prepended triggers a title-max-length violation. Most users don't want this, so we disable linting on Merge and Revert commits by default.

For squash and fixup (including fixup=amend) commits, the rationale is that these are temporary commits that will be squashed into a different commit, and hence the commit messages for these commits are very short-lived and not intended to make it into the final commit history. In addition, by prepending "fixup!", "amend!" or "squash!" to your commit message, certain gitlint rules might be violated (e.g. title-max-length) which is often undesirable.

In case you do want to lint these commit messages, you can disable this behavior by setting the general ignore-merge-commits, ignore-revert-commits, ignore-fixup-commits, ignore-fixup-amend-commits or ignore-squash-commits option to false using one of the various ways to configure gitlint.