← 返回命令列表

Linux command

git-hooks 命令

安全

涉及管道、覆盖或删除,执行前请先确认路径和参数。

常用示例

Create pre-commit hook

echo '#!/bin/sh' > .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit

List available hooks

ls .git/hooks/*.sample

Enable sample hook

mv .git/hooks/pre-commit.sample .git/hooks/pre-commit

说明

Git hooks are scripts that run automatically at key points in the Git workflow. They enable automation of tasks like linting, testing, and commit message validation. Hooks are stored in .git/hooks/ and must be executable. Common hooks include pre-commit (before commit), prepare-commit-msg (edit message), commit-msg (validate message), and pre-push (before push).

FAQ

What is the git-hooks command used for?

Git hooks are scripts that run automatically at key points in the Git workflow. They enable automation of tasks like linting, testing, and commit message validation. Hooks are stored in .git/hooks/ and must be executable. Common hooks include pre-commit (before commit), prepare-commit-msg (edit message), commit-msg (validate message), and pre-push (before push).

How do I run a basic git-hooks example?

Run `echo '#!/bin/sh' > .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

Where can I find more git-hooks examples?

This page includes 3 examples for git-hooks, plus related commands for nearby Linux tasks.