Git:获取深度为1的git存储库的特定版本

时间:2016-04-22 15:31:08

标签: git

如何在不克隆整个存储库的情况下从git存储库获取单个修订

注意:这个问题has been问了几次,但我还没有看到解决问题的答案,因为它们都以“克隆整个git存储库”开头”。在我的用例中无法做到这一点。

我能做的最好的事情是:

  1. 找到提交的depth
  2. 克隆到该深度:git clone --depth $depth $git_repo_url
  3. 结帐并重置:git checkout $commit_hash; git reset --hard
  4. 但是这仍然需要克隆到提交深度。

    有没有办法避免这种情况,只克隆深度为1的特定提交?

2 个答案:

答案 0 :(得分:2)

不是clone而是pull / fetch。看这篇文章:

  1. How to clone git repository with specific revision/changeset?

  2. Retrieve specific commit from a remote Git repository

    git init
    git fetch --depth 1 url://to/source/repository <sha1-of-commit>
    
  3. 并在服务器端设置uploadpack.allowReachableSHA1InWant

答案 1 :(得分:0)

如果你做一个reflog和git cherry-pick

怎么样?