问题
I just want to be able to run it to see if the code in my working tree passes it, without actually attempting a commit.
回答1:
Just run the pre-commit
script through shell:
bash .git/hooks/pre-commit
回答2:
There's a Python package for this available here. Per the usage documentation:
If you want to manually run all pre-commit hooks on a repository, run
pre-commit run --all-files
. To run individual hooks usepre-commit run <hook_id>
.
So pre-commit run --all-files
is what the OP is after.
来源:https://stackoverflow.com/questions/48301280/how-to-manually-run-a-git-pre-commit-hook-without-attempting-a-commit