首先這個(gè)不是pack太大的問題,還是本地倉(cāng)庫(kù)里面有超出遠(yuǎn)程限制大小的文件
但是文件多的時(shí)候不容易發(fā)現(xiàn)。
查找一個(gè)文件夾中大于500M文件的命令:
$ find ./ -type f -size +500M
然后有兩種辦法:
一種就是刪除 .git 目錄,重新建立
一種是重寫所有涉及大文件的歷史版本(網(wǎng)上搜下很多)
這個(gè)和壓縮 pack 的大小無關(guān),但是感覺只有一個(gè)大pack也不好,似乎每次都要上傳很久
git config pack.packSizeLimit 200m
最好的辦法是預(yù)防為主:本地倉(cāng)庫(kù)就不讓有大文件
修改倉(cāng)庫(kù)下的.git/hooks/pre-commit
#!/bin/sh
hard_limit=$(git config hooks.filesizehardlimit)
soft_limit=$(git config hooks.filesizesoftlimit)
: ${hard_limit:=10000000} # 10M
: ${soft_limit:=1000000} # 1M
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