预提交:如何禁用对未暂存文件的检查?

gue*_*tli 7 git pre-commit.com

我的pre-commit.com配置如下所示:

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

Run Code Online (Sandbox Code Playgroud)

如果我尝试提交,我会收到此错误:

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")
Run Code Online (Sandbox Code Playgroud)

我想避免检查未暂存的文件。我知道我在做什么,如果我只想提交一些更改(不是全部),那么我想这样做。

如何禁用对未暂存文件的检查?

Ant*_*ile 9

从您的输出来看,您没有暂存任何要提交的文件。所以git它本身阻止了你提交(不是pre-commit)——如果你实际上不想提交任何东西,你可以使用git commit --allow-empty。如果你想暂存一些文件以供 commit、usegit add或 usegit commit -a

请注意,这里没有错误pre-commit- 只有一个警告,告诉您未暂存的内容已暂时删除,以便可以成功检查部分提交


免责声明:我是预提交的作者

  • 谢谢你!我当时是瞎子。也许预提交在这里可以更明确(对于像我这样的愚蠢和盲目的用户)。 (2认同)