如何在不尝试提交的情况下手动运行git pre-commit钩子?

时间:2018-01-17 12:33:57

标签: githooks

我只是希望能够运行它以查看我工作树中的代码是否通过它,而不是实际尝试提交。

3 个答案:

答案 0 :(得分:24)

只需通过shell运行pre-commit脚本:

bash .git/hooks/pre-commit

答案 1 :(得分:7)

只需运行git commit。您无需在此之前添加任何内容,因此最终您会收到消息no changes added to commit

答案 2 :(得分:3)

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 use pre-commit run <hook_id>.

So pre-commit run --all-files is what the OP is after.