git clone 文件大,depth=1了解

本文介绍了一种使用Git的--depth参数进行浅克隆的方法,该方法可以显著减少克隆大型项目的等待时间和硬盘空间消耗,特别适合于需要快速获取项目最新状态的场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近比较清闲哈~
检查检查Android项目完成情况吧,clone项目漫长的等待,项目文件小2G -_-!!!
对于临时clone项目这是个灾难呀

那么问题来了,如何clone一个轻量级的呢?

查到一个命令 --depth

https://git-scm.com/docs/git-clone
–depth < depth >
Create a shallow clone with a history truncated to the specified number of commits. Implies --single-branch unless --no-single-branch is given to fetch the histories near the tips of all branches. If you want to clone submodules shallowly, also pass --shallow-submodules.

创建一个浅克隆,其历史记录被截断到指定的提交数量。没有给出单分支,会获取所有分支附近的历史记录。如果希望浅克隆子模块,还需要传递–浅子模块。

我们来终端实践一下
$git clone giturl --depth=1
depth用于指定克隆深度,为1表示只克隆最近一次commit.

MBP:Desktop mbp$ git clone https://git.dev.tencent.com/username/Android.git --depth=1
Cloning into 'Android'...
Username for 'https://git.dev.tencent.com': username
Password for 'https://username@git.dev.tencent.com': 
remote: Enumerating objects: 3283, done.
remote: Counting objects: 100% (3283/3283), done.
remote: Compressing objects: 100% (2581/2581), done.
remote: Total 3283 (delta 1203), reused 2183 (delta 513)
Receiving objects: 100% (3283/3283), 198.51 MiB | 761.00 KiB/s, done.
Resolving deltas: 100% (1203/1203), done.
Checking out files: 100% (2980/2980), done.
MBP:Desktop mbp$ 

此时项目文件大小只有几百兆。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值