gpt4 book ai didi

git - 如何防止在 git 中推送大型二进制 blob?

转载 作者:太空狗 更新时间:2023-10-29 13:12:25 26 4
gpt4 key购买 nike

我有一个中央 git 存储库,我自己和几个合作者经常从中推送和 pull 。过去我不小心提交了一个大的二进制 blob,这需要 rebase 才能完全删除,这对每个人来说都是一种痛苦,所以我想防止将来发生这种情况。是否可以在远程存储库中设置一个 Hook 来检查正在推送的文件的文件大小(无论是添加新文件还是更新现有文件)并拒绝超过阈值大小的文件推送,比如 2MB?

重要的是,我希望现有的文件已经大于 2MB,并且是可以容忍的(所以如果一个 2MB 的文件已经在存储库中,推送不应该被拒绝,只有当推送添加一个 2MB 文件或增加一个现有文件时为 2MB)。此外,我希望 Hook 在远程端执行,这样我就不必担心客户端不必设置 Hook 。

编辑:因为一个推送可以包含多个提交,甚至一个包含大文件的提交也会卡在 repo 中,我想防止包含/任何提交/增长到或添加 >=2MB 文件的推送.

最佳答案

听起来像 pre-receive hook将是此检查的正确位置。此 Hook 在推送的服务器端执行,并且可以访问足够的信息来执行文件大小检查。

This hook is invoked by git-receive-pack on the remote repository, which happens when a git push is done on a local repository. Just before starting to update refs on the remote repository, the pre-receive hook is invoked. Its exit status determines the success or failure of the update.

关于git - 如何防止在 git 中推送大型二进制 blob?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11549357/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com