如何防止Git存储库超过最大大小? [英] How to prevent a Git repository growing above a maximum size?
本文介绍了如何防止Git存储库超过最大大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个存储库,您需要在其中控制其大小,如果超出限制,请阻止任何更改.如何实现呢?
There is a repository where you need to control its size and in case of exceeding the limit - block any changes. How to implement this?
推荐答案
.git/hooks/pre-receive
#!/bin/bash
# size limit 2(Gb)
sizelimit_gb=2
reposize_kb=`git count-objects -v | grep 'size-pack' | sed 's/.*\(size-pack:\).//'`
let reposize_b=$reposize_kb*1024
let sizelimit_b=$sizelimit_gb*1024*1024*1024
if [ $reposize_b -gt $sizelimit_b ]; then
echo "Error: repository size > $sizelimit_gb Gb"
exit 1
#else
# echo "<= $sizelimit_gb Gb"
fi
exit 0
以上脚本必须另存为服务器中的 .git/hooks/pre-receive
,并启用执行权限( chmod + x .git/hooks/pre-receive
).
Above script must be saved as .git/hooks/pre-receive
in server, with execution permissions enabled (chmod +x .git/hooks/pre-receive
).
这篇关于如何防止Git存储库超过最大大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文