将 git post-commit 挂钩应用于所有当前和未来的存储库 [英] Applying a git post-commit hook to all current and future repos

查看:27
本文介绍了将 git post-commit 挂钩应用于所有当前和未来的存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个 Git 提交后钩子并且它可以正常工作.但是,我想添加这个钩子以应用于我正在处理的所有当前(和未来)git 存储库.我尝试将钩子添加到我的 ~/.git/hooks/ 而不是项目目录中的 hooks 目录中,但是,这似乎不起作用.

I've written a Git post-commit hook and it works correctly. However, I want to add this hook to apply to all current (and future) git repositories I am working on. I tried adding the hook to my ~/.git/hooks/ instead of in the hooks directory in the project directory, however, this did not seem to work.

有什么方法可以创建适用于我系统上所有存储库的全局 Git 挂钩(无需将它们复制到每个项目目录中)?如果不是,那么最好的解决方案是什么——也许是一个 git-init 模板?

Is there any way to create global Git hooks that will apply to all repositories on my system (without having to copy them into each project directory)? If not, what would be the best solution going forward -- perhaps a git-init template?

推荐答案

我想添加这个钩子以应用于我正在处理的所有当前(和未来)git 存储库

I want to add this hook to apply to all current (and future) git repositories I am working on

使用 git 2.9+(2016 年 6 月),您要做的就是:

With git 2.9+ (June 2016), all you would do is:

git config --global core.hooksPath /path/to/my/centralized/hooks

参见更改默认的 git 钩子":这样做是为了管理集中式钩子.

See "change default git hooks": this has been done to manage centralized hooks.

这篇关于将 git post-commit 挂钩应用于所有当前和未来的存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆