首页 > 其他 > 详细

gitlab重写历史,清理历史大文件

时间:2020-11-25 09:37:34      阅读:172      评论:0      收藏:0      [点我收藏+]

1.导出gitlab上原仓库作为备份。

2.克隆远端仓库代码

git clone http://ip/group/repo.git
cd repo.git

3.拉取仓库的所有分支

git branch -r | grep -v ‘\->‘ | while read remote;do git branch --track 
"${remote#origin/}" "$remote";done
git branch
git tag
git fetch --all
git pull --all

[4.]查找历史大文件(若是知道具体的大文件,不需要查)

     将最大的10个文件查询出来:

git rev-list --objects --all | grep "$(git verify-pack -v .git/objects/pack/*.idx 
| sort -k 3 -n | tail -10 | awk ‘{print $1}‘)"

4.处理记录

git filter-branch --force --index-filter git rm -rf --cached --ignore-unmatch 文件或
目录‘ --prune-empty --tag-name-filter cat -- --all
提示:此过程会在项目根目录生成".git_……"文件夹,里面就是改的记录,且一次只能清理一个文件夹或者文件

5.回收空间

git for-each-ref --format=delete %(refname) refs/original | git update-ref --stdin
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now

6.删除原仓库,新建原仓库的同名仓库,重新关联已清理的仓库,直接推送。

git remote set-url origin http://ip/group/repo.git
git remote -v
git push origin --all
git push origin --tags

至此,垃圾清理完成。

注意:下次开发时需要重新拉取git仓库上的代码,否则还会引入之前大文件的历史记录。

 

gitlab重写历史,清理历史大文件

原文:https://www.cnblogs.com/schblog/p/14033212.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!