Chi*_*hin 55 git shallow-clone
是否可以在存储库中浅层克隆特定提交,即深度为1?就像是
git clone http://myrepo.git 728a4d --depth 1
Run Code Online (Sandbox Code Playgroud)
获取存储库状态,因为它是在SHA提交时728a4d...?
我们的动机是避免必须克隆整个存储库,然后检查特定的提交,当我们只对该特定提交的存储库状态感兴趣时.
ssc*_*rth 49
从Git 2.5.0开始(需要在客户端和服务器端都可用),您可以uploadpack.allowReachableSHA1InWant=true在服务器端设置以启用特定SHA1的获取:
git init
git remote add origin <url>
git fetch --depth 1 origin <sha1>
git checkout FETCH_HEAD
Run Code Online (Sandbox Code Playgroud)
请注意,我没有找到git clone直接执行此操作的语法.
Kir*_*rby 15
注意:我的示例无法通过提交哈希来克隆,但它将有助于克隆标记并具有轻量级存储库.
如果你的"clone"中只有一个提交,并且你将使用commit hash,那么简短的回答是 NO.
我使用这个命令构造(在v2.13.2.windows.1上测试)来标记:
git clone --depth 1 git@github.com:VENDOR/REPO.git --branch 1.23.0 --single-branch
Run Code Online (Sandbox Code Playgroud)
1.23.0 - 它可以是提交哈希值或分支.
完整示例:
$ git clone --depth 1 git@github.com:Seldaek/monolog.git --branch 1.23.0 --single-branch
Cloning into 'monolog'...
remote: Counting objects: 201, done.
remote: Compressing objects: 100% (188/188), done.
remote: Total 201 (delta 42), reused 32 (delta 5), pack-reused 0
Receiving objects: 100% (201/201), 190.30 KiB | 0 bytes/s, done.
Resolving deltas: 100% (42/42), done.
Note: checking out 'fd8c787753b3a2ad11bc60c063cff1358a32a3b4'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
$ cd monolog
Run Code Online (Sandbox Code Playgroud)
.gitdir大小(267K vs 2.6M使用完整clone):
$ du -h --max-depth=0 .git
267K .git
Run Code Online (Sandbox Code Playgroud)
我想表示,--branch可以采取标签/分支.
https://git-scm.com/docs/git-clone#git-clone---branchltnamegt
--branch也可以在结果存储库中的提交处获取标记并分离HEAD.
UPD
简而言之,它可以采取"参考".您可以在这里阅读更多内容:git错误消息"服务器不允许请求未发布的对象"是什么意思?
此外,没有像这样的技巧:
git fetch --depth 1 origin <COMMIT_HASH>
Run Code Online (Sandbox Code Playgroud)
谢谢@BenjiWiebe指责我的错误.
尝试while在 bash 中使用:
git clone --depth=1 $url
i=1; while ! git show $sha1; do git fetch --depth=$((i+=1)); done
Run Code Online (Sandbox Code Playgroud)
这很慢,因为它单独获取每个提交;您可以增加增量(以批量获取提交并提高网络性能),但这仍然是一种蛮力方法。
直接的答案是:你不能。
为什么?详细解释可以在这里找到:为什么没有 Git 克隆特定提交选项?
你还能做什么?
# Create empty repository to store your content
git clone <url>
git reset <sha-1> --hard
Run Code Online (Sandbox Code Playgroud)
更多信息:
git clone <url> --branch <branch_name> --single-branch <folder_name>
git clone <url> --depth=1 --branch <branch_name> --single-branch <folder_name>
正如@sschuberth 所评论的:--depth暗示--single-branch.
使用 fetch 命令代替克隆:
# fetch a commit (or branch or tag) of interest
# In this case you will have the full history of this commit
git fetch origin <sha1>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20224 次 |
| 最近记录: |