浅克隆

克隆一个巨大的存储库(如具有多年历史的项目)可能需要很长时间,或者由于要传输的数据量而失败。如果你不需要提供完整的历史记录,则可以执行浅层克隆:

git clone [repo_url] --depth 1

上面的命令将仅从远程存储库获取最后一次提交。

请注意,你可能无法在浅存储库中解析合并。至少需要提交许多提交通常需要回溯以解决合并,这通常是一个好主意。例如,要获得最后 50 次提交:

git clone [repo_url] --depth 50

稍后,如果需要,你可以获取存储库的其余部分:

Version >= 1.8.3

git fetch --unshallow     # equivalent of git fetch -–depth=2147483647
                          # fetches the rest of the repository

Version < 1.8.3

git fetch --depth=1000    # fetch the last 1000 commits