简体   繁体   English

git lfs 预接收钩子以防止存储库中不需要的文件

[英]git lfs pre-receive hooks to prevent unwanted files in repository

Is it possible to write a server side pre-receive hook to prevent large or binary files to be added to the repository via commits?是否可以编写服务器端预接收钩子来防止通过提交将大文件或二进制文件添加到存储库中?

Locally I can control git-lfs behaviour by adding file types to a .gitattribute file via:在本地,我可以通过将文件类型添加到 .gitattribute 文件来控制 git-lfs 行为:

    git lfs track "*.zip"

This would cause that if a new zip file is added, it will be managed by git-lfs and not committed to the git object store.这将导致如果添加新的 zip 文件,它将由 git-lfs 管理,而不是提交到 git 对象存储。

git-p4 even allows me file size thresholds like: git-p4 甚至允许我设置文件大小阈值,例如:

    largeFileCompressedThreshold = 1m
    largeFileThreshold = 50m

With multiple developers and developing environments it might happen, that one adds such a binary file without configuring git-lfs, hence such a file could be submitted to git directly.对于多个开发人员和开发环境,可能会发生这样的情况,即在不配置 git-lfs 的情况下添加这样的二进制文件,因此可以将这样的文件直接提交给 git。 I would like a server side hook which refuses such a commit and gives a meaningful message, so the developer can easily identify the problem.我想要一个拒绝这种提交并给出有意义的消息的服务器端挂钩,以便开发人员可以轻松识别问题。

Ideally this receive hook would use existing git functionality to parse eg .gitattributes instead of manually parsing all files which are being committed in a script.理想情况下,此接收挂钩将使用现有的 git 功能来解析例如 .gitattributes,而不是手动解析脚本中提交的所有文件。

This could be accomplished using the sizelimit directive of the CheckFile plugin from the Git-Hooks framework.这可以使用Git-Hooks框架中CheckFile插件的 sizelimit 指令来完成。 We use it and it works really well.我们使用它并且效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM