469

Git瘦身,删除历史大文件

找到大文件

git verify-pack -v .git/objects/pack/pack-*.idx | sort -k 3 -g | tail -5

查看文件路径

git rev-list --objects --all | grep <ID>

查看前因后果,历史提交。以public/test.mp4为例

git log --pretty=oneline --branches -- public/test.mp4

如果需要知道commit id所在的分支,使用命令

git branch -a --contains <COMMIT ID>

删除大文件

git filter-branch --force --index-filter 'git rm -rf --cached --ignore-unmatch public/test.mp4' --prune-empty --tag-name-filter cat -- --all
  • filter-branch命令可以用来重写Git仓库中的提交
  • index-filter参数用来指定一条Bash命令,然后Git会检出(checkout)所有的提交, 执行该命令,然后重新提交。
  • all参数表示我们需要重写所有分支(或引用)。

清理和回收空间

rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now

推送到远程服务器

git push origin master --force
或
git push origin --all --force
  • all代表推送所有分支,本地分支也会被推送到远程
文章作者:DOTATONG
发布日期:2023-05-29
# git

评论

暂无

添加新评论