如何处理.git文件过大

由于前阵子git上传了过大的文件,删除后,发现history里面还是有大文件(因为git有版本回退功能,所以将历史文件记录下来了),导致别人在clone的时候非常慢,我采用暴力清除方法,记录下(如果历史commit记录很重要的同学,不要采用此方法,推荐用git branch-filter检查大文件,对应删除大文件即可)。

1.查看文件大小

[[email protected]]# git count-objects -v
count: 0
size: 0
in-pack: 362
packs: 1
size-pack: 8333904
prune-packable: 0
garbage: 0
size-garbage: 0

2.开始删除重建,注意备份

[[email protected]]#rm -rf .git/
[[email protected]]# git init
[[email protected]]# git add -A
[[email protected]]# git commit -m "add all again"
[[email protected]]# git push -f -u origin master

再次查看.git文件大小。

3.遇到报错
问题一:
fatal: This operation must be run in a work tree
Cannot rewrite branches: You have unstaged changes.
解决方法:
git config --unset core.bare

问题二:
Counting objects: 58, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (45/45), done.
Writing objects: 100% (58/58), 4.21 MiB | 0 bytes/s, done.
Total 58 (delta 1), reused 0 (delta 0)
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
解决方法:
git->settings->repository->protected tags修改为unprotect即可
如何处理.git文件过大

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2021-07-13
  • 2022-12-23
猜你喜欢
  • 2021-05-05
  • 2021-04-15
  • 2021-12-13
  • 2021-07-20
  • 2022-03-03
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案