请注意,Git 1.9/2.0(2014 年第一季度)有removed那个限制。
See 提交 82fba2b https://github.com/git/git/commit/82fba2b9d39163a0c9b7a3a2f35964cbc039e1a, from 阮泰玉维 (Nguyễn Thái Ngọc Duy)pclouds) https://github.com/pclouds:
现在 git 支持从浅克隆到浅克隆的数据传输,这些限制不再存在。
The 文档现在显示 https://github.com/git/git/blob/82fba2b9d39163a0c9b7a3a2f35964cbc039e1aa/Documentation/git-clone.txt#L182-L184:
--depth <depth>::
创建一个“浅”克隆,其历史记录被截断为指定的修订数量。
这源于像这样的提交0d7d285 https://github.com/git/git/commit/0d7d285f0e29abb994fe32db87ee81b00f403bd2, f2c681c https://github.com/git/git/commit/f2c681cf12c54ce3859b36693f8a13c36126577b, and c29a7b8 https://github.com/git/git/commit/c29a7b8b3f71c1bede1f57626bafe120280aaea3支持克隆、使用浅克隆发送包/接收包。
smart-http 现在也支持浅层获取/克隆 https://github.com/git/git/commit/16094885ca94f72abc28a915f9aa4021e203a16d.
所有详细信息都在“shallow.c:选择新提交的 8 个步骤.git/shallow https://github.com/git/git/commit/58babfffdeeecaa4d6edecaac1fb0c595218b801".
2015 年 6 月更新:Git 2.5 甚至允许获取单个提交! https://stackoverflow.com/a/30701724/6309
(终极浅案例)
Update January 2016: Git 2.8 (Mach 2016) now documents officially the practice of getting a minimal history.
See commit 99487cf https://github.com/git/git/commit/99487cf228ecba869d2f87f1b55f281fdd1342db, commit 9cfde9e https://github.com/git/git/commit/9cfde9ee8f6dc82365f1e977935960f34108076b (30 Dec 2015), commit 9cfde9e https://github.com/git/git/commit/9cfde9ee8f6dc82365f1e977935960f34108076b (30 Dec 2015), commit bac5874 https://github.com/git/git/commit/bac58749bb2cd04720a4d5a1f58ebc428869f9a2 (29 Dec 2015), and commit 1de2e44 https://github.com/git/git/commit/1de2e442af45acf52ad45f9ac86d4c19f6475590 (28 Dec 2015) by Stephen P. Smith (``) https://github.com/.
(Merged by Junio C Hamano -- gitster -- https://github.com/gitster in commit 7e3e80a https://github.com/git/git/commit/7e3e80a88181c99d33567c05fc865e26f971e954, 20 Jan 2016)
这是 ”Documentation/user-manual.txt https://github.com/git/git/blob/9cfde9ee8f6dc82365f1e977935960f34108076b/Documentation/user-manual.txt#L2131-L2149"
A <<def_shallow_clone,shallow clone>>
通过指定创建git-clone --depth https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---depthltdepthgt switch.
深度可以稍后更改git-fetch --depth https://git-scm.com/docs/git-fetch开关,或恢复完整历史记录--unshallow
.
合并到一个内<<def_shallow_clone,shallow clone>>
只要合并基础在最近的历史中就可以工作。
否则,就像将不相关的历史合并一样,可能会导致巨大的冲突。
此限制可能会使此类存储库不适合在基于合并的工作流中使用。
2020 年更新:
- git 2.11.1 引入了选项
git fetch --shallow-exclude=
以防止获取所有历史记录
- git 2.11.1 引入了选项
git fetch --shallow-since=
以防止获取旧的提交。
有关浅克隆更新过程的更多信息,请参阅“如何更新 git 浅克隆? https://stackoverflow.com/a/41369314/6309".
正如评论者理查德·迈克尔 https://stackoverflow.com/users/420947/richard-michael:
回填历史记录:git pull --unshallow
And 奥勒·哈斯泰特 https://stackoverflow.com/users/2138090/olle-h%C3%A4rstedt adds 在评论中 https://stackoverflow.com/questions/6941889/is-it-safe-to-shallow-clone-with-depth-1-create-commits-and-pull-updates-aga/21217267?noredirect=1#comment82025001_21217267:
回填part历史:git fetch --depth=100
.