背景
如果远程仓库太大,克隆会非常耗时,有时候甚至会报错。
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: the remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
解决办法
git clone 时增加 --depth 参数,进行浅克隆,只克隆指定数量的历史记录。
git clone --depth=1 https://github.com/test/test.git
代表只克隆最近一次 commit 的分支
浅克隆后怎么获取完整内容?
-
将浅层存储库转换为完整存储库
git pull --unshallow
或者git fetch --unshallow
-
修改 .git 文件夹内 config 文件的 [remote "origin"] 部分的内容如下
[remote "origin"]
url = https://xxx.com/abc/xxx.git
fetch = +refs/heads/*:refs/remotes/origin/*
也可直接用命令修改: git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
- 获取所有分支
git fetch -pv
网友评论