栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何限制提交时的文件大小?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何限制提交时的文件大小?

此预提交的挂钩将执行文件大小检查:

.git / hooks / pre-commit

#!/bin/shhard_limit=$(git config hooks.filesizehardlimit)soft_limit=$(git config hooks.filesizesoftlimit): ${hard_limit:=10000000}: ${soft_limit:=500000}list_new_or_modified_files(){    git diff --staged --name-status|sed -e '/^D/ d; /^D/! s/.s+//'}unmunge(){    local result="${1#"}"    result="${result%"}"    env echo -e "$result"}check_file_size(){    n=0    while read -r munged_filename    do        f="$(unmunge "$munged_filename")"        h=$(git ls-files -s "$f"|cut -d' ' -f 2)        s=$(git cat-file -s "$h")        if [ "$s" -gt $hard_limit ]        then env echo -E 1>&2 "ERROR: hard size limit ($hard_limit) exceeded: $munged_filename ($s)" n=$((n+1))        elif [ "$s" -gt $soft_limit ]        then env echo -E 1>&2 "WARNING: soft size limit ($soft_limit) exceeded: $munged_filename ($s)"        fi    done    [ $n -eq 0 ]}list_new_or_modified_files | check_file_size

上面的脚本必须另存为

.git/hooks/pre-commit
启用执行权限(
chmod +x .git/hooks/pre-commit
)。

默认的软(警告)和硬(错误)大小限制设置为500,000和10,000,000字节,但可以分别通过

hooks.filesizesoftlimit
hooks.filesizehardlimit
设置覆盖它们:

$ git config hooks.filesizesoftlimit 100000$ git config hooks.filesizehardlimit 4000000


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/391755.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号