How to apply client-side hook to all local repositories in git?

独自空忆成欢 提交于 2019-12-03 16:02:58
David Cain

The problem in your steps:

You made a bad symbolic link. The commit-msg symbolic link points to .git/hooks/.hooks/commit-msg. Instead, try this:

$ cd myrepo
$ mkdir .hooks
$ cd .git/hooks
$ mv commit-msg ../../.hooks/commit-msg
$ ln -s !$ commit-msg  # lazy: '!$' expands to '../../.hooks/commit-msg'

How to restrict each developer's commit message

As you know, the commit-msg hook is a client-side hook. If you want each developer's commit messages to be rejected if they don't follow some scheme, you need to have the developers install the hook themselves. You can't maintain hooks as part of your repository, but keeping them in another Git repo is an option. (To be clear, you could keep them in your repository, but your developers would still need to make symlinks in the .git/hooks directory, as you have).

If you truly want to force developers to be restricted by a hook, look into server-side hooks. You could use pre-receive, for example, to check that all pushed commit messages obey your scheme.

Chapter 8.3 (Customizing Git - Git Hooks) of Pro Git is an excellent resource. There are some quality walk-throughs there to help you. You can also take a look at the example files included in .git/hooks for your repository.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!