问题描述:
今天发现gitea仓库推送到某个镜像仓库的操作几个月前已经报错终止推送了,报错如下:
首先翻译报错提示可知是因为git仓库大小超过1G限制。检查本地.git文件,发现.git文件大小已达到1.13G。确定是.git文件过大导致,可考虑删除旧的历史.git提交记录。
推送失败:超出上下文截止时间-远程:Powered byI[01;33mGITEE.COM I[0m[1.1.5] 远程:设置跟踪标志 9245f491 远程。仓库大小:1127.660MB,超出配额 1024MB 远程:推送被拒绝。存储库大小超出限制 远程:帮助链接https://gitee.com/help/articles/4232 远程:存储库垃圾回收:https://gitee.com/oangkns/settinas#ait-ac 远程:企业远程:由action"atns"aneecomt提供 跟踪标志9245f491 远程П[01-33mGITEE.COM存储库大小:1127.660MB 存储配额1024MB 远程:推送被拒绝!
存储库 [大小:1127.660MB] 远程:Helolink 仓库大小:https://gitee.com/help/articles/4232 远程:存储库GC:https://gitee.com/luoluoyu 1/giyangkms/settings#qit-gc 远程:企业版:https://gitee.com/enterpris 远程:由conae9UI01-33MGITEE.COM提供技术支持 跟踪标记:9245f491 远程:推送被拒绝 远程:Helolink 仓库大小:https://gitee.com/help/articles/4232 远程:存储库GC:https://gitee.com/luoluoyu 1/aivangkms/settings#ait-ac 远程:企业版:https://gitecommerces
问题解决:
解决方案1)考虑删除旧的超过一年的git仓库记录
如果你想删除 Gitea 仓库中超过一年前的历史记录,只保留最近一年的提交,可以使用 git filter-repo
工具来实现。以下是一个详细的步骤:
1. 安装 git filter-repo
git filter-repo
是一个强大的工具,可以帮助你重写 Git 历史记录。
pip install git-filter-repo
2. 克隆仓库(可选,建议备份)
在进行操作之前,建议克隆一个完整备份,以防出现问题。
git clone --mirror http://127.0.0.1:3000/TEST/myweb.git new-repo.git
3. 删除超过一年的历史记录
使用 git filter-repo
删除超过一年前的提交,只保留最近一年的记录。
(1) 进入新的仓库目录
cd new-repo.git
(2) 运行清理旧数据命令
git filter-repo --commit-callback '
import datetime
timestamp_str = commit.committer_date.decode().split()[0]
commit_date = datetime.datetime.fromtimestamp(int(timestamp_str))
current_date = datetime.datetime.now()
if (current_date - commit_date).days > 365:skip_commit = True
' --force
(3) 强制推送到远程仓库
git remote set-url origin <remote-repo-url>
git push origin --force --all
git push origin --force --tags
(4) 优化仓库
git gc --prune=now --aggressive
4. 优化仓库
清理仓库中的未引用对象,进一步减小 .git
目录大小。
(1) 运行 git gc
git gc --prune=now --aggressive
(2) 更新远程仓库
如果需要优化远程仓库,可以强制推送:
git push origin --force --all
git push origin --force --tags
5. 验证结果
检查仓库的历史记录,确保超过一年的提交已被删除:
git log --oneline
6. 注意事项
- 备份仓库:在进行任何操作之前,确保备份完整的仓库数据。`
- 团队协作:删除历史记录会影响所有开发人员,确保提前通知并协调。
- 权限管理:如果仓库是共享的,确保你有足够的权限进行强制推送。
通过以上步骤,你可以成功删除超过一年的历史记录,只保留最近一年的提交,从而减小 .git
目录的大小。
解决方案2)丢弃所有git仓库提交记录。重新克隆代码建立新的git仓库。
略
附:查看仓库大文件路径:
[root@localhost .git]# git rev-list --objects --all | while read -r hash path; do size=$(git cat-file -s "$hash"); echo "$size $hash $path"; done | sort -n | tail -5
3945546 c1ad45760dbcf34159ae8cb00873121e62b285af public/font/hyngt.ttf
5261205 a669ebe712cc929b689884b8ddcef830c3b2650a public/apk/sgb.apk
5780472 6f4be5c4866655addc61aee28e171a2b376f7471 public/uploads/home/store/goods/1/1_2023102315172822343.mp4
43093716 cca485f6c67deff00798792d3de85a64d170e6fa vendor.zip
957612815 dae9e0f50fe2012f9220539c8429381a0677c862 public.zip
参考文件:
仓库体积过大,如何减小? - Gitee.com