Git钩子脚本可以和存储库一起管理吗?
本文翻译自:Can Git hook scripts be managed along with the repository?
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/
. Git的钩子脚本通常存储在<project>/.git/hooks/
。 However, those scripts are not propagated when people do a clone and they are not version controlled. 但是,当人们进行克隆时,这些脚本不会传播,并且不受版本控制。
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? 我可以仅使这些挂钩脚本指向我的存储库中的版本控制脚本吗?
#1楼
参考:https://stackoom.com/question/1n8R/Git钩子脚本可以和存储库一起管理吗
#2楼
How about git-hooks , it route .git/hooks
invoke into script under project directory githooks
. git-hooks怎么样,它将.git/hooks
调用路由到项目目录githooks
下的脚本中。
There are also lot of features to enable you minimize copy and symlink hook all over the place. 还有很多功能可以使您在各处最小化复制和符号链接挂钩。
#3楼
如果您的项目是JavaScript项目,并且您将npm
用作软件包管理器,则可以使用shared-git-hooks在npm install
上强制执行githooks。
#4楼
In Git 2.9 , the configuration option core.hooksPath
specifies a custom hooks directory. 在Git 2.9中 ,配置选项core.hooksPath
指定一个自定义钩子目录。
Move your hooks to a hooks
tracked directory in your repository. 将您的挂钩移动到存储库中hooks
跟踪的目录中。 Then, configure each instance of the repository to use the tracked hooks
instead of $GIT_DIR/hooks
: 然后,将存储库的每个实例配置为使用跟踪的hooks
而不是$GIT_DIR/hooks
:
git config core.hooksPath hooks
In general, the path may be absolute, or relative to the directory where the hooks are run (usually the working tree root; see DESCRIPTION section of man githooks
). 通常,路径可以是绝对路径,也可以是相对于运行钩子的目录的路径(通常是工作树的根目录;请参见man githooks
部分)。
#5楼
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
. 从理论上讲,您可以使用所有脚本在项目目录中创建一个hooks
目录(或任何您喜欢的名称),然后在.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). 当然,每个克隆该存储库的人都必须设置这些符号链接(尽管您可能真的很喜欢,并且拥有一个部署脚本,克隆程序可以运行该脚本来半自动设置它们)。
To do the symlink on *nix, all you need to do is: 要在* nix上执行符号链接,您需要做的是:
root="$(pwd)"
ln -s "$root/hooks" "$root/.git/hooks"
use ln -sf
if you're ready to overwrite what's in .git/hooks
如果您准备覆盖.git/hooks
的内容,请使用ln -sf
#6楼
pre-commit
makes this easy for pre-commit hooks. pre-commit
使预提交挂钩变得容易。 Doesn't answer the OP's question about managing any arbitrary git hook, but pre-commit hooks are probably the most frequently used for code quality purposes. 没有回答OP有关管理任意git钩子的问题,但是预提交钩子可能是最常用于代码质量目的的钩子。
Git钩子脚本可以和存储库一起管理吗?相关推荐
- 另一个git进程似乎在这个存储库中运行
我正在尝试学习如何使用Git,并创建了一个包含HTML,CSS和Javascript文件的小项目. 我从我的基本空项目中创建了一个分支,然后对我的代码进行了一些更改. 我尝试暂存更改,但我收到以下错误 ...
- Git 基础知识 - 记录对存储库的更改
记录对存储库的更改 检查文件的状态 跟踪新文件 暂存已修改的文件 短路状态 忽略文件 查看暂存和未暂存更改 提交更改 跳过暂存区域 删除文件 移动文件 此时,您应该在本地计算机上有一个真正的 Git ...
- git之如何为github存储库获取sha256哈希码
我正在尝试为git hub回购构建一个condo程序包,它需要一个" sha256"哈希码,我如何才能获得git repo示例的sha256.GitHub - jensengrou ...
- 将现有Git存储库推送到SVN
我一直在用Git完成所有工作并推送到GitHub. 我对软件和网站都非常满意,我不想在此时改变我的工作方式. 我的博士生顾问要求所有学生将他们的工作保存在大学托管的SVN存储库中. 我已经找到大量关于 ...
- 尝试远程添加Git存储库时收到“致命错误:不是git存储库”
我通过遵循本教程向自己介绍Git: 让jekyll在Nearlyfreespeech.net上运行 一切正常,直到将回购添加到本地计算机的部分为止: git remote add nfsn ssh:/ ...
- 如何将空目录添加到Git存储库?
如何将空目录(不包含文件)添加到Git存储库? #1楼 你不能 请参阅Git常见问题解答 . 当前,git索引(临时区域)的设计仅允许列出文件,并且没有足够的能力来进行更改以允许空目录的人已经足够在意 ...
- 您如何合并两个Git存储库?
请考虑以下情形: 我在自己的Git存储库中开发了一个小型实验项目A. 它现在已经成熟,我希望A成为较大项目B的一部分,该项目B具有自己的大型存储库. 我现在想将A添加为B的子目录. 如何将A合并为B, ...
- 如何将Git存储库克隆到特定文件夹?
git clone git@github.com:whatever执行git clone git@github.com:whatever命令git clone git@github.com:whate ...
- 在Windows上忽略Git存储库中的目录
如何在Windows上使用msysgit忽略Git中的目录或文件夹? #1楼 似乎忽略文件和目录有两种主要方法: .gitignore 将.gitignore文件放入.git文件夹之外的存储库的根.g ...
最新文章
- 关于Synchronized研伸扩展
- WCF传递强类型DataSet【源码】
- windows ubuntu Android studio安装好启动没反应解决方法
- python代码学习-数据处理图片加遮挡、噪声、模糊
- 前后端开发是怎么合作分工的
- sudo mysql压缩备份解压操作_高效管理文件之压缩及解压缩 .bz2 文件
- 厉害|高通正利用“AI Engine”加速AI从云端走向终端应用和落地!
- java只读xml文件头_为了生成只读的接口和xml,并命名结尾为MapperR.java和MapperR.xml...
- ios 关于自定义navigationItem,实现右侧多个按钮
- xml文件的三种解析方式 DOM SAM PULL
- C++ Segmentation fault 一般原因
- Nik Collection 3.0.8 Mac/Win PS/LR超强调色滤镜合集Nik3插件中文版+中文视频教程
- python简单操作excel
- java.io.NotSerializableException错误解决方法
- go语言中的type关键字
- 物联网:断点续传策略及流程图
- 同花顺程序交易接口实现类
- 风险投资(VC)与私募股权投资(PE)的区别
- 使用JavaCC生成解析器(前言)
- ilove中文_【iLovePDF下载】iLovePDF在线版 v0.9.662 中文版-开心电玩
热门文章
- Steve Thair谈DevOps on Windows的演变与面临的挑战
- Android网络编程5之OkHttp2.x用法全解析
- Python3之Django框架搭建详细步骤
- 《精通Wireshark》—第1章1.5节抓取信息的方式
- js创建对象时,属性加引号与不加引号的区别(转)
- [self addChild:gameLayer z:1 tag:LayerTagGameLayer] z值含义
- CLR via C#, Third Edition图书推荐及下载
- GoAhead WebServer 架构
- 验证GridControl Gridview 单元格。
- 以Crypto++实现RSA加解密二进制数据