使用Husky添加预提交钩子,而无需向git推送附加内容 [英] Adding precommit hooks with Husky without pushing addition to git
问题描述
嘿,我想将脚本添加到我的package.json
中,但不想在git中添加此脚本,因为它会影响我的同事的项目行为.
Hey i want to add a script to my package.json
but don't want to check in this addition to our git because it affects the behaviour of the project for my colleagues.
我要添加的脚本是由husky处理的precommit-Hook.是否有可能像package.override.json这样的地方定义脚本并忽略.gitignore中的文件,或者有其他方法吗?
The script i want to add is a precommit-Hook which is handled by husky. Is there a possibility to have something like a package.override.json where i define the script and ignore the file in .gitignore or are there different approaches?
推荐答案
我可以想到两个不使用husky
的解决方案:
I can think of two solutions without using husky
:
您可以直接在本地存储库的.git/hooks
文件夹中设置自己的git挂钩.参见 https://git-scm.com/book/gr/v2/Customizing-Git-Git-Hooks 获取有关如何执行此操作的信息.
You can set up your own git hooks directly in the .git/hooks
folder of your local repository. See https://git-scm.com/book/gr/v2/Customizing-Git-Git-Hooks for information on how to do that.
如果那不能解决您的问题,并且您正在运行* nix操作系统,则可以始终使用bash编写自己的提交别名.添加类似
If that doesn't work out you and you're running a *nix OS, can always write your own commit alias using bash. Add something like
alias commit="npm run test && git commit"
到您的~/.bashrc
文件.
(当然,理想的是使您的同事相信赫斯基提供的价值.)
(Of course, the ideal is to convince your colleagues of the value husky provides.)
这篇关于使用Husky添加预提交钩子,而无需向git推送附加内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!