如何在不克隆整个存储库的情况下从git存储库获取单个修订?
注意:这个问题has been问了几次,但我还没有看到解决问题的答案,因为它们都以“克隆整个git存储库”开头”。在我的用例中无法做到这一点。
我能做的最好的事情是:
depth
。git clone --depth $depth $git_repo_url
。 git checkout $commit_hash; git reset --hard
。但是这仍然需要克隆到提交深度。
有没有办法避免这种情况,只克隆深度为1的特定提交?
答案 0 :(得分:2)
不是clone
而是pull
/ fetch
。看这篇文章:
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>
并在服务器端设置uploadpack.allowReachableSHA1InWant
。
答案 1 :(得分:0)
如果你做一个reflog和git cherry-pick
怎么样?