在github或gitlab克隆项目时,因项目太大git clone会报错,如下:
image
解决的办法为:
$ git clone https://github.com/xxx/xxx.git --depth=1
--depth
用来指定克隆的深度,1表示克隆最近的一次commit。
这种方法克隆的项目只包含最近的一次commit的一个分支,体积很小。
需要将该分支所有的commit克隆下来的话,可以用下面的命令:
$ git fetch --unshallow
但会产生另外一个问题,他只会把默认分支clone下来,其他远程分支并不在本地,所以这种情况下,需要用如下方法拉取其他分支:
$ git clone --depth 1 https://github.com/dogescript/xxxxxxx.git
$ 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
https://blog.csdn.net/kunyus/article/details/104658351/