git同步二进制文件会导致本地和远程仓库大小成倍增长,进而导致自动同步失败。使用如下脚本来控制仓库大小。
注意,清理操作会造成所有提交历史log完全删除,不可恢复,建议提前备份(只针对.git文件夹,不会影响工作区文件)
# # 每次推送检查仓库.git文件夹大小,需要定期在远程仓库gc
sizes=(`du -d0 .git`)
if [ ${sizes[0]} -gt 800000 ]
then
# 注意,此操作会造成所有提交历史log完全删除,不可恢复,建议提前备份
git checkout --orphan latest_branch # 新建空分支
mongodump -d leanote -o leanote_db
cp -r /home/changhonghe/github/leanote/files ./
git add -A -v >> git.log
git commit -m "update`date`"
git branch -D master
git branch -m master
git push -f origin master >> git.log
date >> git.log
git branch --set-upstream-to=origin/master
else
# 大小较小使用常规增量更新,提高效率
mongodump -d leanote -o leanote_db
cp -r /home/changhonghe/github/leanote/files ./
git add . -v >> git.log
git commit -m "update"
git push >> git.log
date >> git.log
fi