'Can I ignore flake8 errors by passing a git commit flag?

I have aflake8:check todo pre-commit hook, which I want to ignore for now.

I can ignore everything if I git commit --no-verify but I do want all other hooks to run

I also can edit my .pre-commit-hooks.yaml to remove the relevant hook, but I do want it. Just not now...

Is it possible to skip this hook check just for this commit / push?


My config .pre-commit-config.yaml:

default_language_version:
    python: python3.6
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v4.1.0 # 4.2.0 drops python<3.7
  hooks:
  - id: check-added-large-files
  - id: check-case-conflict
  - id: check-docstring-first
  - id: check-executables-have-shebangs
  - id: check-toml
  - id: check-merge-conflict
  - id: check-yaml
  - id: debug-statements
  - id: end-of-file-fixer
  - id: mixed-line-ending
  - id: sort-simple-yaml
  - id: trailing-whitespace
- repo: local
  hooks:
  - id: todo
    name: Check TODO
    language: pygrep
    args: [-i]
    entry: TODO
    types: [text]
    exclude: ^(.pre-commit-config.yaml|.github/workflows/test.yml)$
- repo: https://gitlab.com/pycqa/flake8
  rev: 3.9.2
  hooks:
  - id: flake8
    # P103 - disallows "{}" in strings
    # E203 - ":" with whitespace before it
    # E501 - line length (black will handle most of the issues, and what it can't - should be ingored)
    args: ["-j8", "--ignore=E203,E501,P103"]
    additional_dependencies:
    - flake8-broken-line
    - flake8-bugbear
    - flake8-comprehensions
    - flake8-debugger
    - flake8-string-format
- repo: https://github.com/PyCQA/isort
  rev: 5.10.1
  hooks:
  - id: isort
    args: ["--profile", "black"] # solves conflicts between black and isort
- repo: https://github.com/psf/black
  hooks:
  - id: black
  rev: 22.3.0


Solution 1:[1]

That's actually the exact case described in the docs:

Not all hooks are perfect so sometimes you may need to skip execution of one or more hooks. pre-commit solves this by querying a SKIP environment variable. The SKIP environment variable is a comma separated list of hook ids. This allows you to skip a single hook instead of --no-verifying the entire commit.

$ SKIP=flake8 git commit -m "foo"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dominik Sta?czak