Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pre-commit: How to disable the check for unstaged files?

My pre-commit.com config looks like this:

repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v3.2.0
    hooks:
    -   id: trailing-whitespace
    -   id: end-of-file-fixer
    -   id: check-yaml
    -   id: check-added-large-files
-   repo: https://gitlab.com/pycqa/flake8
    rev: ''  # pick a git hash / tag to point to
    hooks:
    -   id: flake8
-   repo: https://github.com/pre-commit/mirrors-isort
    rev: v5.7.0
    hooks:
    - id: isort

If I try to commit I get this error:

guettli@yoga15:~/projects/foo$ LANG=C git commit

[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to /home/guettli/.cache/pre-commit/patch1611141286.
Trim Trailing Whitespace.............................(no files to check)Skipped
Fix End of Files.....................................(no files to check)Skipped
Check Yaml...........................................(no files to check)Skipped
Check for added large files..........................(no files to check)Skipped
flake8...............................................(no files to check)Skipped
isort................................................(no files to check)Skipped
[INFO] Restored changes from /home/guettli/.cache/pre-commit/patch1611141286.

On branch feature/super-foo
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   .gitignore

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    .pre-commit-config.yaml

no changes added to commit (use "git add" and/or "git commit -a")

I would like to avoid the checking for unstaged files. I know what I do, and if I only want to commit some changes (not all), then I want to do this.

How to disable the check for unstaged files?

like image 333
guettli Avatar asked Apr 07 '26 08:04

guettli


1 Answers

From your output, you didn't stage any files for commit. so git itself prevented you from committing (not pre-commit) -- if you actually wanted to commit nothing you can use git commit --allow-empty. If you want to stage some files for commit, use git add, or use git commit -a

Note that there were no errors from pre-commit here -- only a warning telling you that unstaged things were temporarily removed so that partial commits can be linted successfully.


disclaimer: I'm the author of pre-commit

like image 158
Anthony Sottile Avatar answered Apr 08 '26 21:04

Anthony Sottile



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!