Git 浅克隆

2021-02-18  本文已影响0人  teletian

背景

如果远程仓库太大,克隆会非常耗时,有时候甚至会报错。

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 的分支

浅克隆后怎么获取完整内容?

  1. 将浅层存储库转换为完整存储库
    git pull --unshallow 或者 git fetch --unshallow

  2. 修改 .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/*"

  1. 获取所有分支
    git fetch -pv
上一篇 下一篇

猜你喜欢

热点阅读