git - 为什么 git shallow clone 可以比 <depth> 有更多的提交?

标签 git git-clone

git clone --depth <depth> <url> <repo>; git -C <repo> rev-list --count --all != <depth>

git clone --depth <depth>: Create a clone with a history truncated to <depth> commits. Implies --single-branch.

例如网址 = https://github.com/vhf/free-programming-books.git , depth = 10, 但 commit_count = 15

git version 2.9.0

最佳答案

存储库的浅版本包括在跟随所有可能的父而不是仅第一个时,距分支头指定距离内的所有提交。因此,对于具有 merge 的非线性历史记录,提交计数将不等于深度。

$ git clone --depth 10 https://github.com/vhf/free-programming-books.git
Cloning into 'free-programming-books'...
remote: Counting objects: 85, done.
remote: Compressing objects: 100% (63/63), done.
remote: Total 85 (delta 31), reused 46 (delta 22), pack-reused 0
Unpacking objects: 100% (85/85), done.
Checking connectivity... done.

$ git -C free-programming-books/ rev-list --count HEAD
15

$ git -C free-programming-books/ log --graph --oneline --decorate
* b9ffc8e (HEAD -> master, origin/master, origin/HEAD) Adding pt_BR C book used by ...
* 824c1d3 Replaced Google Python style guide dead-link with new one (#1987)
* 3c32612 Added Laravel: Code Smart online book (#1986)
* eabce2c Fixed typo: Structure and Interpretation (#1985)
* aab83e5 Added IRPF90 gitbook to Misc section (#1984)
* 6f72509 Added a bash tutorial in free-courses-en.md (#1983)
*   9b95b09 Merge branch 'pr/1980'
|\  
| * 2811cd3 Fix blank lines
| * bbe9bd6 Adds 2 golang podcasts (and fixes missing #ggulp)
| * fdeabc6 (grafted) Fix ordering
*   da317ad Merge branch 'pr/1976'
|\  
| * 20b940a Fix ordering
| * 9a6ee0b (grafted) Add openHPI to list of MOOCs
* 43294d1 Update link Rust by Example #1970 (#1995)
* d758a93 (grafted) Fix a broken link to 'Practical PostgreSQL' (#1994)

此截断历史中的伪根提交是 d758a93 , 9a6ee0b , 和 fdeabc6 . 他们都是头犯的第9代祖。


原始答案(在提供 MVCE 之前)

<url> 时,本地克隆可能就是这种情况。不以 file:// 开头.然后git输出相应的警告:

warning: --depth is ignored in local clones; use file:// instead.

对于本地克隆,git 只是创建到源存储库中对象的硬链接(hard link)(除非指定了 --no-hardlinks 开关,但后者仍然不会使本地克隆遵守 --depth 选项)。通过硬链接(hard link)进行克隆可以节省磁盘空间,并且与复制所有对象相比速度非常快。由于 --depth 的目的选项是减少数据传输,它对本地克隆没有多大意义,因此被忽略。

关于git - 为什么 git shallow clone 可以比 <depth> 有更多的提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38683512/

相关文章:

git shallow clone - 我如何删除 "grafted tag"它是什么?

git - 连接后从代理收到 HTTP 代码 501

git - git 克隆是空的?为什么会这样

git - 防止 git 要求提交更改

git - stash Git 错误 "fatal: remote error: CAPTCHA required"

git - 统一同一存储库的两个本地副本的分支

linux - Git 克隆失败 : Server Certificate Verification Failed

git - 在 Git 中,你如何检查你从命令行推送到 Github 中的哪个仓库?

gitkraken 'refs/heads/master' 落后于 'refs/remotes/origin/master'

node.js - 如何在使用 git remote url 进行 npm install 时指定注册表?