Git 淺克隆

背景

如果遠程倉庫太大,克隆會非常耗時,有時候甚至?xí)箦e。

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 參數(shù),進行淺克隆,只克隆指定數(shù)量的歷史記錄。
git clone --depth=1 https://github.com/test/test.git 代表只克隆最近一次 commit 的分支

淺克隆后怎么獲取完整內(nèi)容?

  1. 將淺層存儲庫轉(zhuǎn)換為完整存儲庫
    git pull --unshallow 或者 git fetch --unshallow

  2. 修改 .git 文件夾內(nèi) config 文件的 [remote "origin"] 部分的內(nèi)容如下

[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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容