#!/bin/bash # Git仓库清理脚本 - 清理历史大文件 # 作者:张翔 # 日期:2026-03-31 echo "🚀 开始执行Git仓库清理..." # 备份当前分支 echo "📋 备份当前分支..." git branch git-cleanup-backup 2>/dev/null || echo "⚠️ 备份分支已存在" # 1. 清理dist.tar.gz文件(1GB大文件) echo "🗑️ 清理dist.tar.gz文件..." git filter-branch --force --index-filter 'git rm -rf --cached --ignore-unmatch dist.tar.gz' --prune-empty HEAD # 2. 清理package-lock.json大文件 echo "🗑️ 清理package-lock.json大文件..." git filter-branch --force --index-filter 'git rm -rf --cached --ignore-unmatch package-lock.json' --prune-empty HEAD # 3. 清理.next目录 echo "🗑️ 清理.next目录..." git filter-branch --force --index-filter 'git rm -rf --cached --ignore-unmatch .next' --prune-empty HEAD # 4. 清理e2e快照文件 echo "🗑️ 清理e2e快照文件..." git filter-branch --force --index-filter 'git rm -rf --cached --ignore-unmatch e2e/src/tests/visual' --prune-empty HEAD # 5. 清理test-framework报告 echo "🗑️ 清理test-framework报告..." git filter-branch --force --index-filter 'git rm -rf --cached --ignore-unmatch test-framework' --prune-empty HEAD # 6. 清理大字体文件 echo "🗑️ 清理大字体文件..." git filter-branch --force --index-filter 'git rm -rf --cached --ignore-unmatch public/fonts/AoyagiReisho.ttf' --prune-empty HEAD # 7. 清理Git引用日志 echo "🧹 清理Git引用日志..." git reflog expire --expire=now --all # 8. 强制垃圾回收 echo "🗑️ 强制垃圾回收..." git gc --prune=now --aggressive # 9. 清理临时备份 echo "🗑️ 清理临时备份..." rm -rf .git/refs/original/ rm -rf .git/logs/ # 10. 显示清理结果 echo "" echo "📊 Git仓库清理完成!" echo "📦 当前Git仓库大小:" du -sh .git echo "" echo "✅ Git仓库清理完成!" echo "💡 建议:" echo " 1. 将清理后的仓库推送到远程:git push --force --all" echo " 2. 更新远程origin:git push --force --tags" echo " 3. 在.gitignore中添加以下规则:" echo " dist.tar.gz" echo " package-lock.json" echo " .next/" echo " e2e/src/tests/visual/" echo " test-framework/" echo " public/fonts/*.ttf"