Git:获取深度为1的特定版本的git存储库 [英] Git: get a particular revision of a git repository with depth 1

查看:214
本文介绍了Git:获取深度为1的特定版本的git存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


$ b 注意 :这个问题 问了100多次,但我还没有看到答案解决它,因为它们都是从克隆整个git存储库开始的。这不能在我的用例中完成。



我能做的最好的是:


  1. 找到提交的深度

  2. 克隆直到该深度: git clone --depth $ depth $ git_repo_url
  3. 签出并重置: git checkout $ commit_hash; git reset --hard

但这仍然需要克隆到提交深度。



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

解决方案

不与克隆但与 / fetch 。看到这篇文章:


  1. 如何使用特定版本/变更集克隆git仓库?

  2. 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:

  1. Find the depth of the commit.
  2. Clone until that depth: git clone --depth $depth $git_repo_url.
  3. 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:

  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>
    

And set uploadpack.allowReachableSHA1InWant on the server side.

这篇关于Git:获取深度为1的特定版本的git存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆