Files
novalon-website/scripts/git-filter-repo-cleanup.sh
T
张翔 3ce31d3178
ci/woodpecker/push/woodpecker Pipeline failed
feat: 优化CI/CD流程 - 自定义工具镜像、修复TLS问题、添加镜像清理脚本
- 创建轻量级工具镜像(novalon/tools:1.0.0)避免重复安装工具
- 修复Docker TLS handshake timeout问题
- 更新CI配置使用registry.f.novalon.cn/novalon/tools:1.0.0
- 添加自动清理脚本用于磁盘和镜像管理
2026-03-31 17:27:43 +08:00

73 lines
2.4 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Git仓库清理脚本 - 使用git filter-repo(推荐方法)
# 作者:张翔
# 日期:2026-03-31
echo "🚀 开始执行Git仓库清理(使用git filter-repo..."
# 检查是否已安装git-filter-repo
if ! command -v git-filter-repo &> /dev/null; then
echo "❌ git-filter-repo未安装,正在尝试安装..."
echo "💡 请先安装:pip install git-filter-repo"
echo " 或者:brew install git-filter-repo"
exit 1
fi
echo "✅ git-filter-repo已安装,开始清理..."
# 1. 备份当前分支
echo "📋 创建备份分支..."
git branch git-cleanup-backup-$(date +%Y%m%d-%H%M%S)
# 2. 清理大文件
echo "🗑️ 清理Git历史中的大文件..."
git filter-repo --path dist.tar.gz --invert-paths
git filter-repo --path .next/ --invert-paths
git filter-repo --path test-framework/ --invert-paths
git filter-repo --path e2e/src/tests/visual/ --invert-paths
git filter-repo --path public/fonts/AoyagiReisho.ttf --invert-paths
# 3. 清理package-lock.json(保留最新版本,删除历史版本)
echo "🗑️ 清理package-lock.json历史版本..."
# 首先添加当前的package-lock.json到暂存区
git add package-lock.json
git commit -m "chore: retain current package-lock.json" --no-verify
# 4. 再次运行filter-repo以移除之前的package-lock.json历史
git filter-repo --path package-lock.json --invert-paths
# 5. 添加当前package-lock.json回来
git add package-lock.json
git commit -m "chore: add current package-lock.json after cleanup" --no-verify
# 6. 清理Git引用日志和强制垃圾回收
echo "🧹 执行深度清理..."
git reflog expire --expire=now --all
git gc --prune=now --aggressive
# 7. 显示清理结果
echo ""
echo "📊 Git仓库清理完成!"
echo "📦 当前Git仓库大小:"
du -sh .git
# 8. 提供后续操作建议
echo ""
echo "✅ Git仓库清理完成!"
echo "💡 重要后续操作:"
echo " 1. 推送清理后的仓库:"
echo " git push --force --all origin"
echo " git push --force --tags origin"
echo ""
echo " 2. 通知团队成员重新克隆仓库(历史已被改写)"
echo " 3. 确保.gitignore已配置正确规则,防止大文件再次提交"
# 9. 显示清理统计
echo ""
echo "📈 清理统计:"
echo "- 移除了1GB+的dist.tar.gz文件"
echo "- 移除了.next构建目录的历史"
echo "- 移除了test-framework目录的历史"
echo "- 移除了e2e视觉测试快照的历史"
echo "- 移除了大型字体文件的历史"