[英]Git: get a particular revision of a git repository with depth 1
How do I obtain a single revision from a git repository without cloning the whole repository ? 如何在不克隆整个存储库的情况下从git存储库获得单个修订版?
Note : this question has been asked 100s of times but I have yet to see an answer that solves it since they all start with "clone the whole git repository". 注意 :这个问题已经 被问过一百次了,但是我还没有找到解决这个问题的答案,因为它们都始于“克隆整个git仓库”。 This cannot be done in my use case. 在我的用例中无法做到这一点。
The best I can do is: 我能做的最好的事情是:
depth
of the commit. 查找提交的depth
。 git clone --depth $depth $git_repo_url
. 克隆到该深度: git clone --depth $depth $git_repo_url
。 git checkout $commit_hash; git reset --hard
检出并重置: git checkout $commit_hash; git reset --hard
git checkout $commit_hash; git reset --hard
. git checkout $commit_hash; git reset --hard
。 But this still requires cloning up to the commits depth. 但这仍然需要克隆到提交深度。
Is there a way to avoid that and clone only a particular commit with depth 1? 有没有办法避免这种情况,只克隆深度为1的特定提交?
Not with clone
but with pull
/ fetch
. 不是clone
而是pull
/ fetch
。 See this post: 看到这篇文章:
How to clone git repository with specific revision/changeset? 如何克隆具有特定修订/变更集的git存储库?
Retrieve specific commit from a remote Git repository 从远程Git存储库中检索特定的提交
git init git fetch --depth 1 url://to/source/repository <sha1-of-commit>
And set uploadpack.allowReachableSHA1InWant
on the server side. 并在服务器端设置uploadpack.allowReachableSHA1InWant
。
如果您进行reflog和git cherry-pick怎么样
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.