更改默认的git钩子 [英] change default git hooks

查看:114
本文介绍了更改默认的git钩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定这是否可能在git中(我没有找到它,但我可能在我的搜索中使用了错误的词汇表),但是能够修改和启用钩子作为所有新的默认值存储库(在创建时我的意思是),因此每次创建新存储库时都不必定制这些存储库。看起来,实现这一点的简单方法是编写一个封装器来设置我的钩子,并在创建新的存储库时对它们进行chmod操作,但是如果有一种方式构建到git中,我宁愿使用它,而不是使用不必要的包装器脚本,而不是使用不必要的包装器脚本。

Not sure if this is possible in git (I haven't found it but I may be using the wrong vocabulary in my searches), but it be would useful to be able to modify and enable hooks as the defaults for all new repositories (at the time of creation I mean) so these don't have to be customized each time a new repository is created. It seems the easy way to do this is write a wrapper that sets my hooks and chmods them when I create a new repository, but if there's a way built into git I would rather use that instead of having unnecessary wrapper scripts however little lying around.

澄清从评论复制到现在删除的答案:

我的问题是,是否可以更改所有新存储库的默认行为,因此不需要每次为每个新存储库都以相同方式对其进行自定义。简单的答案是编写一个用于创建和定制repos的包装器(它会生成钩子脚本并chmods它们),但是似乎这种默认行为也应该可以自定义,而不必这样做。

My question is whether the default behavior for ALL new repositories can be changed, so they don't need to be customized in the same way each time for each new repository. The easy answer is write a wrapper for creating and customizing the repos (it generates the hook scripts and chmods them), but it seems like this default behavior should also be customizable without having to do that.

推荐答案

git-init 手册页(也适用于 git-clone

From the git-init man page (also works with git-clone if you are cloning an existing repo instead of creating a new one from scratch):


       --template=<template_directory>
           Provide the directory from which templates will be used. The
           default template directory is /usr/share/git-core/templates.

           When specified, <template_directory> is used as the source of the
           template files rather than the default. The template files include
           some directory structure, some suggested "exclude patterns", and
           copies of non-executing "hook" files. The suggested patterns and
           hook files are all modifiable and extensible.

您可以修改系统范围的模板目录(默认为 / usr / share / git-core /您可以在命令行上提供 - template =< template_directory> ,但是可能位于机器的不同位置您可以创建或克隆回购,或者您可以在配置文件中配置默认​​的模板目录:

You can modify the system-wide template directory (which defaults to /usr/share/git-core/templates, but may be in a different location on your machine), you can supply --template=<template_directory> on the command line when you create or clone the repo, or you can configure the default template directory in your config file:

[init]
     templatedir = /path/to/templates

这篇关于更改默认的git钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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