簡體   English   中英

為什么 git 淺克隆可以有更多的提交<depth> ?

[英]Why git shallow clone can have more commits than <depth>?

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

git clone --depth <depth> :創建一個歷史記錄被截斷為<depth> commits的克隆。 暗示--single-branch

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

git version 2.9.0

當跟隨所有可能的父級而不是僅第一個時,存儲庫的淺版本包括距分支頭指定距離內的所有提交。 因此,對於具有合並的非線性歷史記錄,提交計數將不等於深度。

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

此截斷歷史記錄中的偽根提交是d758a939a6ee0bfdeabc6 他們都是頭目提交的第9代祖先。


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

<url>不以file://開頭時,本地克隆可能就是這種情況。 然后git輸出相應的警告:

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

對於本地克隆,git 只是創建指向源存儲庫中對象的硬鏈接(除非指定了--no-hardlinks開關,但后者仍然不會使本地克隆尊重--depth選項)。 通過硬鏈接進行克隆可以節省磁盤空間,並且與復制所有對象相比速度非常快。 由於--depth選項的目的是減少數據傳輸,它對本地克隆沒有多大意義,因此被忽略。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM