Git 挂钩管理

发布于 2024-08-17 09:53:19 字数 222 浏览 14 评论 0原文

我们在项目中使用自定义编写的 Git 挂钩。

Hooks 存储在项目的存储库中,当它们发生更改时,要获取新版本,每个用户必须将它们手动复制到他的 .git/hooks 目录中。这是比较不方便的。

改进这一点的一种方法是使 .git/hooks 成为工作树的符号链接。但这意味着每个分支(甚至是正在开发的用户本地功能分支)应该具有最新版本的钩子。这也不方便。

你会如何解决这个问题?

We use custom-written Git hooks in our project.

Hooks are stored in a project's repository, and, when they do change, to get a new version each user must copy them manually in his .git/hooks directory. This is rather inconvenient.

One way to improve this is to make .git/hooks a symlink into worktree. But this would imply that each branch (even user's local feature branches under development) should have the most current version of hooks. This is not convenient as well.

How would you solve the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

ぶ宁プ宁ぶ 2024-08-24 09:53:19

维护一个单独的钩子存储库和符号链接。

我同意,如果 Git 有一个用于传播 hooks 脚本的内置机制就好了,但它没有。

Maintain a separate repository of your hooks and symlink into that.

I agree, it'd be nice if Git had a built-in mechanism for propagating hooks scripts but it doesn't.

糖果控 2024-08-24 09:53:19

http://benjamin-meyer.blogspot .com/2010/06/managing-project-user-and-global-git.html 似乎是一种自动化钩子符号链接的便捷方法,以促进全局、每个用户和每个项目的钩子。

http://benjamin-meyer.blogspot.com/2010/06/managing-project-user-and-global-git.html appears to be a convenient way to automate hook symlinking, to facilitate global, per user, and per project hooks.

雨夜星沙 2024-08-24 09:53:19

在 Git 2.9 中,您可以使用 core.hooksPath 配置指向自定义钩子目录。

Git 2.9 发行说明 - https://github.com/blog /2188-git-2-9-has-been-released

提及 core.hooksPath 的文档 - https://git-scm.com/docs/githooks

注意 - 这个问题可能与 Git hook 脚本可以与存储库一起管理吗?

In Git 2.9, you can point to a custom hooks directory using the core.hooksPath configuration.

Git 2.9 Release Notes - https://github.com/blog/2188-git-2-9-has-been-released

Documentation mentioning core.hooksPath - https://git-scm.com/docs/githooks

Note - this question is a possible duplicate of Can Git hook scripts be managed along with the repository?

久隐师 2024-08-24 09:53:19

pre-commit 有很多看起来很有前途的功能

  • 适用于多种语言,并且有一个插件架构可以添加支持其他语言
  • 能够引导挂钩依赖项(取决于语言)
  • 增量应用挂钩(仅对属于提交一部分的更改运行挂钩)
  • 利用 init.templateDir 所以签出的存储库会自动安装正确的钩子
  • 使用环境变量暂时禁用特定的钩子 - 不要跳过所有检查只是因为您无法运行其中之一

源代码此处

pre-commit has a bunch of features that look promising

  • Works for many languages, and has a plugin architecture to add support for other languages
  • Capable of bootstrapping the hook dependencies (language dependent)
  • Applies hooks incrementally (only run hooks on changes that are part of the commit)
  • Leverages the init.templateDir so newly checked out repos automatically install the correct hooks
  • Temporarily disable a specific hook using an environment variable - don't skip all the checks just because you can't run one of them

Source code here

小…楫夜泊 2024-08-24 09:53:19

对于基于 NodeJS 的项目,我建议您查看 ghooks

For NodeJS-based projects, I suggest you taking a look at ghooks.

殤城〤 2024-08-24 09:53:19

您可以将存储库的 .git 目录设为 git 存储库,然后向其中添加钩子和其他配置,添加 objectsrefs 等. 目录和文件,例如 index 到其 .gitignore。不仅如此,您还可以设置一个接收后挂钩来从其来源更新元存储。一旦设置了初始配置,您就可以让它引入更新,而无需任何额外的工作。

我正在研究这个细节,比如忽略列表中应该包含哪些内容;我将结果保存在 此存储库 的分支中。

You could make the repository's .git directory a git repository, and just add hooks and other config to it, adding the objects, refs, etc. directories and files like index to its .gitignore. Not only that, but you could set up a post-receive hook to update the metarepo from its origin. Once you had the initial configuration set up, you could have it pull in updates without any additional effort.

I'm working out the details of this, like what should go in the ignore list; I'm keeping the results in branches of this repo.

浅沫记忆 2024-08-24 09:53:19

我们将 .git/hooks 创建为工作树的符号链接。

对于极少数情况下,当有人需要提交钩子将拒绝的文件时,我们使用 git commit --no-verify

We made .git/hooks a symlink into the working tree.

For those rare occasions when someone needs to commit files that the hooks will reject, we use git commit --no-verify

浪推晚风 2024-08-24 09:53:19

命令 git config core.hooksPath $CUSTOM_GIT_HOOKS_PATH 会将您的钩子路径设置为所需的文件夹; 您可以为多个 git 进行配置,并为所有这些 git 使用相同的挂钩脚本

如果您想要全局挂钩配置,
git config --global core.hooksPath $CUSTOM_GIT_HOOKS_PATH

用于在 VSCode 中管理 GitHooks,您可以尝试我的扩展 GitHooks

GitHooks VSCode 市场链接

Command git config core.hooksPath $CUSTOM_GIT_HOOKS_PATH will set your hooks path to the required folder; you can configure this for multiple gits and use the same hook scripts for all of them

if you want global hooks configuration
git config --global core.hooksPath $CUSTOM_GIT_HOOKS_PATH

for managing your GitHooks inside VSCode you can try out my extension GitHooks

GitHooks VSCode Marketplace Link

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文