且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将我的预提交钩子添加到现有的git存储库中

更新时间:2021-12-20 09:10:34

检查一下,我的同事可以立即将其安装到位

checking it out my colleagues have it instantly in place

9月. 2015 :这是不可能的:可以在源代码管理中放入一个钩子(您只需将脚本复制到git repo中),但是在克隆/签出时它不能自动就位"(活动):太危险了,具体取决于钩子实际在做什么.
另请参见" Git远程/共享的预提交钩子"

Sept. 2015: That is not possible: a hook can be put in source control (you simply copy the script in your git repo), but it cannot be "automatically in place" (active) on clone/checkout: that would be way too dangerous, depending on what the hook is actually doing.
See also "Git remote/shared pre-commit hook"

您仍然需要通过将符号链接(即使在Windows中)添加到git repo中存在的预提交钩子来激活它.

You would still need to activate it, by adding a symlink (even on Windows) to the pre-commit hook present in the git repo.

2016年12月更新: OP Calamity Jane 提到

我现在已经在symfony2项目中解决了它(并与其他项目一起使用),将其作为composer.json的一部分.
因此,如果同事正在执行composer installcomposer update,则会自动将其放置在正确的位置.

I solved it by now in symfony2 projects (and with others, it also should work) to have it as part of the composer.json.
So if a colleague is doing a composer install or composer update, it is automatically placed in the correct place.

"scripts": { "dev-install": [ "bash setup_phpcs.sh" ] }, 

因此在开发人员中,会自动调用setup_phpcs.sh并将钩子从存储库中的文件夹复制到正确的位置.
而且由于该挂钩是存储库的一部分,因此可以轻松地对其进行更新和分发.

So on dev, setup_phpcs.sh is automatically called and that copies the hook from a folder in the repository to the right place.
And since the hook is part of the repository it can be easily updated and distributed.

Hi-Angel

所述/32649628/如何添加我的预提交钩子以连接到现有的git存储库/32649801?noredirect = 1#comment98243078_32649801>评论:

As noted by Hi-Angel in the comments:

我发现:Emacs具有带有钩子的build-aux目录,并且在运行autogen.sh时,所有钩子都从那里复制.

I figured that out: Emacs has build-aux dir with hooks, and, upon running autogen.sh, all hooks are copied from there.