如何处理git项目过大的问题

主宰稳场 提交于 2020-03-25 12:16:58

3 月,跳不动了?>>>

起因

原本代码是在本地部署的gitlab,想迁移到阿里云code。但是阿里云限制项目大小2GB,因为项目好几年且代码都是build原因我们的前端项目远远超过了2GB。

我尝试了下面方法并没有什么效果 参考GitLab 如何清理历史大文件? 清理Git库中历史上的大文件或含密码文件,参考 https://rtyley.github.io/bfg-repo-cleaner/ 如果还不行,参考 https://github.com/rtyley/bfg-repo-cleaner/issues/65

解决

==警告== 该方法只保留最后一次提交的版本

如果默认分支是master

// depth用于指定克隆深度,为1即表示只克隆最近一次commit.
git clone --depth 1 git@git.gitlab.com:frontend/apps.git
cd apps
// 删除老的git
rm -rf .git
// 在阿里云code新建项目apps
git init
git remote add origin git@code.aliyun.com:frontend/apps.git
git commit -a -m 'init'
git push origin master

如果你不是master分支?

默认只会把默认分支clone下来,其他远程分支并不在本地,所以这种情况下,需要用如下方法拉取其他分支

git remote set-branches origin remote_branch_name
git fetch --depth 1 origin remote_branch_name
git checkout remote_branch_name

https://www.jianshu.com/p/1031dd2a6c3a

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!