问题
Is it possible to set up pre-commit-hooks in the server repo and have them download to the clients when the repo is cloned?
回答1:
From git-scm:
The hooks are all stored in the
hooks
subdirectory of the Git directory. In most projects, that’s.git/hooks
.
Recall that .git/
is managed locally.
So, no, there is no programmatic way using only git to force a repository to install hooks when it is cloned.
That said, a common practice is to bundle hooks into a folder like hooks/
within your repository, and then either
- explain how to install them in the README, or
- provide a script which will install them after cloning that the user has to run manually.
If you have rules you wish to validate, which you could use to smoke-test if someone has used a hook, you can install pre-receive
hook in your remote.
For example, if you have a pre-commit hook that prepends a branch identifier to commit messages, you could check in a pre-recieve hook (actually on the 'server') that commit messages start with a branch identifier.
来源:https://stackoverflow.com/questions/47182740/setting-pre-commit-hook-server-side