使用 --depth 1 进行浅层克隆、创建提交并再次拉取更新是否安全?

发布于 2024-11-27 19:10:27 字数 543 浏览 1 评论 0 原文

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

提笔落墨 2024-12-04 19:10:27

请注意,Git 1.9/2.0(2014 年第 1 季度)已删除该限制。
请参阅 提交 82fba2b,来自 阮泰玉Duy(pclouds

既然 git 支持从浅克隆到浅克隆的数据传输,这些限制就不再存在了。

文档现在如下

--depth <depth>::

创建一个“浅”克隆,其历史记录被截断为指定的修订数量。

这源于诸如 0d7d285f2c681cc29a7b8 支持克隆、使用浅克隆发送包/接收包。
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"

<> 是通过指定 git-clone --深度开关。
稍后可以使用 git-fetch --depth 开关,或使用 --unshallow 恢复完整历史记录。

只要合并基础位于最近的历史记录中,<> 内的合并就可以工作。
否则,就像将不相关的历史合并一样,可能会导致巨大的冲突。
此限制可能会使此类存储库不适合在基于合并的工作流程中使用。

2020 年更新:

  • git 2.11.1 引入了选项 git fetch --shallow-exclude= 以防止获取所有历史记录
  • git 2.11.1 引入了选项 git fetch --shallow-since=以防止获取旧的提交。

有关浅克隆更新过程的更多信息,请参阅“如何更新 git 浅克隆?”。


正如理查德·迈克尔评论的那样:

回填历史记录:git pull --unshallow

Olle Härstedt 添加 在评论中

要回填历史记录的部分git fetch --depth=100

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):

Now that git supports data transfer from or to a shallow clone, these limitations are not true anymore.

The documentation now reads:

--depth <depth>::

Create a 'shallow' clone with a history truncated to the specified number of revisions.

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"

A <<def_shallow_clone,shallow clone>> is created by specifying the git-clone --depth switch.
The depth can later be changed with the git-fetch --depth switch, or full history restored with --unshallow.

Merging inside a <<def_shallow_clone,shallow clone>> will work as long as a merge base is in the recent history.
Otherwise, it will be like merging unrelated histories and may have to result in huge conflicts.
This limitation may make such a repository unsuitable to be used in merge based workflows.

Update 2020:

  • git 2.11.1 introduced option git fetch --shallow-exclude= to prevent fetching all history
  • git 2.11.1 introduced option git 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:

to backfill history: git pull --unshallow

And Olle Härstedt adds in the comments:

To backfill part of the history: git fetch --depth=100.

番薯 2024-12-04 19:10:27

查看我的类似问题的一些答案 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 to init a repo, set up a remote tracking branch (you do want the one branch only?), and then fetch that single branch, which feels long winded with more opportunity for mistakes.

Edit: For the 'clone' step see this answer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文