为什么不能 git add .git/hooks/my-hook
我希望在给定存储库的克隆中始终存在一些钩子。有没有办法在存储库的 .git/hooks 中添加文件?
谢谢
I would like to have some hooks always present in a clone of a given repository. Is there a way to add a file in .git/hooks in the repository?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以在 git 模板中定义自己的钩子,但即使在那里,这些钩子也将是不可执行的。
即,一旦克隆存储库,用户仍然必须激活它们(重命名或激活可执行位)。
这样,在没有他/她完全知情和明确批准的情况下,所述用户将不会执行任何不需要的脚本。
否则,对于任何“盲目”克隆存储库的人来说都会面临太大的安全风险。
It is possible to define your own hooks in a git template, but even there, those hooks would be non-executable ones.
I.e. the user would still have to activate them (rename or activate the executable bit) once the repo is cloned.
That way, said user won't have any unwanted script executed without his/her full knowledge and explicit approval.
Doing otherwise would be too much of a security risk for anyone "blindly" cloning a repo.
对我来说听起来像是一个安全风险。仅仅因为您克隆了某个存储库并不意味着您想赋予它执行代码的权利。
您可以将钩子的副本放入版本化代码中,并包含一些脚本文件,以允许用户轻松地将它们复制到他的钩子目录中。当然,如果你安装了钩子,你可以使用它们来保持最新状态。
Sounds like a security risk to me. Just because you clone some repository doesn't mean you want to give it the right to execute code.
You could put a copy of hooks into the versioned code and include some script file to allow the user to copy them to his hooks directory easily. And of course one you have hooks installed you can use them to keep themselves up-to-date.