当我“推”的时候,Git 钩子是否被推到了遥控器上?

如果在 repo/中在本地存储库中创建一个新的 hook 脚本。Git/hook/post-commit 然后运行“ git push”钩子是否被推送到远程?然后,当其他开发人员从相同的起源运行“ git pull”时,他们会得到我的新钩子吗?

41467 次浏览

No, git hooks are not pushed or pulled, as they are not part of the repository code.

Please refer to the documentation for a list of simple client-side and server-side hooks.

If you want to enable some hooks for all clients that clone or pull from a given repository, you have to add the hooks to your codebase and then create your own script to copy them into, or link to them from repo/.git/hooks/.

No. Hooks are per-repository and are never pushed. Similarly, the repo config isn't pushed either, nor is anything in .git/info, or a number of other things.

Pushing and pulling only exchanges branches/tags and commit objects (and anything reachable from a commit, e.g. trees, blobs).

Sadly no but since git 2.9 you can place them into .githooks folder (as others mentioned) and run:

git config --local core.hooksPath .githooks/

So no need to create symlinks or copy files.