跳转到内容

mise generate git-pre-commit ​

Generate a git hook that runs a mise task

The hook runs mise run <TASK> (default pre-commit) with the staged file names in the STAGED environment variable. It prints the hook unless you pass --write, which saves it in the repository's hooks directory and makes it executable.

For hooks that git gives a message file (commit-msg, prepare-commit-msg, applypatch-msg, sendemail-validate), the task gets that file as an argument. Other hook arguments, such as a pre-push hook's remote name and URL, are not passed on.

For a full git hook manager, see hk: https://hk.jdx.dev

参数 ​

  • [-- MISE_ARG]… — 要嵌入生成的钩子中的 mise 标志,写在 -- 之后

    这些参数会插入到 mise 和 run 之间,因此钩子会携带你在命令行中传递的相同上下文。当配置文件不在仓库根目录时很有用,因为 git 会从顶层目录运行钩子:-- -C subdir 会让钩子找到它。

Flags ​

  • -t --task <TASK> — The task to run when the hook is triggered

    Default: pre-commit

  • -w --write — Write the hook to the hooks directory and make it executable

    The hooks directory is .git/hooks, or core.hooksPath when it is set. An existing hook of the same name is moved to <HOOK>.old.

  • --hook <HOOK> — Which git hook to write, such as pre-push

    默认值: pre-commit

  • -h --help — 打印帮助

示例 ​

Install the hook; each commit then runs mise run pre-commit

mise generate git-pre-commit --write --task=pre-commit

Use the config in subdir, since git runs hooks from the repository root

mise generate git-pre-commit --write -- -C subdir

相关文档 ​