起因
原本代码是在本地部署的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