Git 钩子脚本可以与存储库一起管理吗? [英] Can Git hook scripts be managed along with the repository?

查看:34
本文介绍了Git 钩子脚本可以与存储库一起管理吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们想制作一些我们都可以共享的基本钩子脚本——用于诸如预格式化提交消息之类的事情.Git 具有通常存储在 /.git/hooks/ 下的钩子脚本.但是,当人们进行克隆时,这些脚本不会传播,并且它们不受版本控制.

We'd like to make a few basic hook scripts that we can all share -- for things like pre-formatting commit messages. Git has hook scripts for that that are normally stored under <project>/.git/hooks/. However, those scripts are not propagated when people do a clone and they are not version controlled.

有什么好的方法可以帮助每个人获得正确的钩子脚本吗?我可以让这些钩子脚本指向我的 repo 中的版本控制脚本吗?

Is there a good way to help everyone get the right hook scripts? Can I just make those hook scripts point to version controlled scripts in my repo?

推荐答案

理论上,您可以在包含所有脚本的项目目录中创建一个 hooks 目录(或您喜欢的任何名称),然后在 .git/hooks 中符号链接它们.当然,每个克隆 repo 的人都必须设置这些符号链接(尽管您可能非常喜欢并拥有一个部署脚本,克隆程序可以运行该脚本以半自动地设置它们).

Theoretically, you could create a hooks directory (or whatever name you prefer) in your project directory with all the scripts, and then symlink them in .git/hooks. Of course, each person who cloned the repo would have to set up these symlinks (although you could get really fancy and have a deploy script that the cloner could run to set them up semi-automatically).

要在 *nix 上做符号链接,你需要做的就是:

To do the symlink on *nix, all you need to do is:

root="$(pwd)"
ln -s "$root/hooks" "$root/.git/hooks"

如果你准备好覆盖 .git/hooks

这篇关于Git 钩子脚本可以与存储库一起管理吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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