git clone
中的 --depth 1
选项:
创建一个浅克隆,其历史记录被截断为指定的修订数量。浅存储库有许多限制(您不能从中克隆或获取,也不能从其中推入或推入其中),但如果您只对具有悠久历史的大型项目的最近历史感兴趣,并且想要以补丁形式发送修复程序。
但我已经成功地完成了浅层克隆,提交了一些更改并将这些更改推回到(裸克隆)原点。
这对我来说很有意义——我的意思是为什么不呢?当克隆的 HEAD 在源中可识别时,并且我的提交位于此之上,似乎没有理由。但手册上却另有说法。
我喜欢浅层克隆的想法 - 例如 drupal 核心:当我从 7 开始时,我不需要知道 drupal 4 中发生了什么。 - 但我不想搬起石头砸自己的脚。
那么浅层克隆、在其中开发提交、再次拉取以跟上原始更新是否安全?
The --depth 1
option in git clone
:
Create a shallow clone with a history truncated to the specified number of revisions. A shallow repository has a number of limitations (you cannot clone or fetch from it, nor push from nor into it), but is adequate if you are only interested in the recent history of a large project with a long history, and would want to send in fixes as patches.
But I've successfully done a shallow clone, committed some changes and pushed those changes back to the (bare clone) origin.
It makes sense to me - I mean why not? when the cloned HEAD is identifiable in the origin, and my commit comes on top of this, there seems no reason. But the manual says otherwise.
I like the idea of shallow clone - e.g. of drupal core: there's no way I need to know what went on in drupal 4 when I've started from 7. - but I don't want to shoot myself in the foot.
So is it safe to shallow clone, develop commits in it, pull again to keep up with updates from origin?
发布评论
评论(2)
请注意,Git 1.9/2.0(2014 年第 1 季度)已删除该限制。
请参阅 提交 82fba2b,来自 阮泰玉Duy(
pclouds
):文档现在如下:
这源于诸如 0d7d285、f2c681c 和 c29a7b8 支持克隆、使用浅克隆发送包/接收包。
smart-http 现在也支持浅层获取/克隆。
所有详细信息都在“
shallow.c
中:选择新的8个步骤提交.git/shallow
”。2015 年 6 月更新:Git 2.5 甚至允许获取单个提交!
(终极浅层案例)
2016 年 1 月更新:Git 2.8(2016 年马赫)现在正式记录了获取最小历史记录的实践。
请参阅提交99487cf,提交 9cfde9e(2015 年 12 月 30 日),提交 9cfde9e(2015 年 12 月 30 日),提交 bac5874(2015 年 12 月 29 日),以及 提交 1de2e44(2015 年 12 月 28 日),作者:斯蒂芬·P·史密斯 (``)。
(由 Junio C Hamano --
gitster
-- 合并于 提交 7e3e80a,2016 年 1 月 20 日)这是“
文档/user-manual.txt
"2020 年更新:
git fetch --shallow-exclude=
以防止获取所有历史记录git fetch --shallow-since=
以防止获取旧的提交。有关浅克隆更新过程的更多信息,请参阅“如何更新 git 浅克隆?”。
正如理查德·迈克尔评论的那样:
和 Olle Härstedt 添加 在评论中:
Note that Git 1.9/2.0 (Q1 2014) has removed that limitation.
See commit 82fba2b, from Nguyễn Thái Ngọc Duy (
pclouds
):The documentation now reads:
That stems from commits like 0d7d285, f2c681c, and c29a7b8 which support clone, send-pack /receive-pack with/from shallow clones.
smart-http now supports shallow fetch/clone too.
All the details are in "
shallow.c
: the 8 steps to select new commits for.git/shallow
".Update June 2015: Git 2.5 will even allow for fetching a single commit!
(Ultimate shallow case)
Update January 2016: Git 2.8 (Mach 2016) now documents officially the practice of getting a minimal history.
See commit 99487cf, commit 9cfde9e (30 Dec 2015), commit 9cfde9e (30 Dec 2015), commit bac5874 (29 Dec 2015), and commit 1de2e44 (28 Dec 2015) by Stephen P. Smith (``).
(Merged by Junio C Hamano --
gitster
-- in commit 7e3e80a, 20 Jan 2016)This is "
Documentation/user-manual.txt
"Update 2020:
git fetch --shallow-exclude=
to prevent fetching all historygit fetch --shallow-since=
to prevent fetching old commits.For more on the shallow clone update process, see "How to update a git shallow clone?".
As commented by Richard Michael:
And Olle Härstedt adds in the comments:
查看我的类似问题的一些答案 why-cant-i-push -from-a-shallow-clone 以及 git 列表上最近线程的链接。
最终,存储库之间的“深度”测量并不一致,因为它们是从各自的 HEAD 测量的,而不是(a)您的 Head,或(b)您克隆/获取的提交,或(c)其他东西你心里有数。
困难的地方是让用例正确(即自洽),以便分布式的,因此可能不同的存储库仍然可以愉快地一起工作。
它看起来确实像
checkout --orphan
是正确的“设置”阶段,但仍然缺乏关于“克隆”步骤的干净(即简单易懂的一行命令)指导。相反,看起来您必须init
一个存储库,设置一个remote
跟踪分支(您确实只想要一个分支?),然后fetch 那个单一分支,感觉很冗长,而且有更多出错的机会。
编辑:有关“克隆”步骤,请参阅此答案< /a>
See some of the answers to my similar question why-cant-i-push-from-a-shallow-clone and the link to the recent thread on the git list.
Ultimately, the 'depth' measurement isn't consistent between repos, because they measure from their individual HEADs, rather than (a) your Head, or (b) the commit(s) you cloned/fetched, or (c) something else you had in mind.
The hard bit is getting one's Use Case right (i.e. self-consistent), so that distributed, and therefore probably divergent repos will still work happily together.
It does look like the
checkout --orphan
is the right 'set-up' stage, but still lacks clean (i.e. a simple understandable one line command) guidance on the "clone" step. Rather it looks like you have toinit
a repo, set up aremote
tracking branch (you do want the one branch only?), and thenfetch
that single branch, which feels long winded with more opportunity for mistakes.Edit: For the 'clone' step see this answer