Git:获取深度为1的特定版本的git存储库 [英] Git: get a particular revision of a git repository with depth 1
问题描述
如何在不克隆整个存储库的情况下从git存储库获得单个修订版本?
$ b 注意 :这个问题有 已问了100多次,但我还没有看到答案解决它,因为它们都是从克隆整个git存储库开始的。这不能在我的用例中完成。
我能做的最好的是:
- 找到提交的
深度
。 - 克隆直到该深度:
git clone --depth $ depth $ git_repo_url
。
- 签出并重置:
git checkout $ commit_hash; git reset --hard
。
- 签出并重置:
但这仍然需要克隆到提交深度。
有没有办法避免这种情况,并且只克隆深度为1的特定提交?
不与克隆
但与拉
/ fetch
。看到这篇文章:
- href =https://stackoverflow.com/questions/14872486/retrieve-specific-commit-from-a-remote-git-repository>从远程Git仓库检索特定的提交
git init
git fetch --depth 1 url:// to / source / repository< sha1-of-commit>
并设置 uploadpack .allowReachableSHA1InWant
在服务器端。
How do I obtain a single revision from a git repository without cloning the whole repository?
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". This cannot be done in my use case.
The best I can do is:
- Find the
depth
of the commit. - Clone until that depth:
git clone --depth $depth $git_repo_url
. - Checkout and reset:
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?
Not with clone
but with pull
/fetch
. See this post:
How to clone git repository with specific revision/changeset?
Retrieve specific commit from a remote Git repository
git init git fetch --depth 1 url://to/source/repository <sha1-of-commit>
And set uploadpack.allowReachableSHA1InWant
on the server side.
这篇关于Git:获取深度为1的特定版本的git存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!