Git:如何直接从远程存储库存档?

Hou*_*man 24 git

我通常使用下面的命令project.git来获取指定目标中的存档:

git archive master | tar -x -C /home/kave/site/
Run Code Online (Sandbox Code Playgroud)

我想知道是否可以直接从远程存储库归档到目标目录?

我尝试过这样的事情,没有任何乐趣:

git archive master https://kave@dndigital.git.cloudforge.com/myoproject.git | tar -x -C /home/kave/site/
Run Code Online (Sandbox Code Playgroud)

有什么建议?谢谢

mga*_*aia 32

来自git help archive:

   --remote=<repo>
       Instead of making a tar archive from the local repository, retrieve a tar archive from a remote repository.
Run Code Online (Sandbox Code Playgroud)

命令最终会像:

$ git archive --remote=https://kave@dndigital.git.cloudforge.com/myoproject.git master
Run Code Online (Sandbox Code Playgroud)

但是,如果您只是提取回购,您可以使用以下--depth参数进行浅层克隆git clone:

   --depth <depth>
       Create a shallow clone with a history truncated to the specified number of revisions. A shallow repository has a number of limitations (you cannot clone or fetch from it, nor push from nor into it), but is adequate if you are only interested in the recent history of a large project with a long history, and would want to send in fixes as patches.
Run Code Online (Sandbox Code Playgroud)

所以你有这样的事情:

$ git clone --depth=1 https://kave@dndigital.git.cloudforge.com/myoproject.git
Run Code Online (Sandbox Code Playgroud)

  • @Robru:我认为这应该是一个独立的问题,但在`git help clone`中读到` - [no-] single-branch`.我认为像`git clone --depth = 1 --single-branch --branch TARGET_BRANCH REMOTE_URL`之类的东西.而且,谢谢 - 我以前从未想过这个:) (7认同)
  • 无法从 Github 存档:`您似乎正在使用 ssh 来克隆一个 git:// URL。`您可以查找这篇 [文章](https://www.gilesorr.com/blog/git-archive-github) .html)了解更多详情。 (5认同)
  • 当尝试通过 HTTP 从 Github 存档时,您还可能会收到错误“致命:协议不支持操作”。解决方案与 @SiminJie 链接的文章相同:Github 提供了 tarball 下载服务,因此请使用它。 (2认同)