git clone –depth 1 是浅克隆(shallow clone),只拉取最近一次提交的历史记录,而不是整个仓库的完整历史。
主要好处:
下载速度快,节省带宽和磁盘空间
适合只想获取最新代码、不关心历史记录的场景
比如一个有几千次提交的大仓库,完整克隆可能要几百 MB,用 –depth 1 可能只需要几十 MB。
常见用法:
只拉最新一次提交
git clone –depth 1 https://github.com/user/repo.git
拉最近 10 次提交
git clone –depth 10 https://github.com/user/repo.git
缺点是你看不到完整的 commit 历史,也没法切换到旧的分支或标签。如果后续需要完整历史,可以用 git fetch –unshallow 补全。

