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

36

我通常使用如下命令在我的 project.git 中获取指定目标的归档:

git archive master | tar -x -C /home/kave/site/
我想知道是否可以直接从远程存储库归档,而不是放在目标目录中?
我尝试了类似下面这样的方法,但没有成功:
git archive master https://kave@dndigital.git.cloudforge.com/myoproject.git | tar -x -C /home/kave/site/

有什么建议吗?谢谢


Git 1.9/2.0(2014年第一季度)将通过浅克隆实现更高效的操作:https://dev59.com/W2w05IYBdhLWcg3w6GLH#21217267 和 https://dev59.com/52Ik5IYBdhLWcg3wWs9z#21217326。 - VonC
对于 GitHub 存储库,您可以考虑使用 gh repo archive <repository> - VonC
2个回答

43

以下内容来自git help archive

   --remote=<repo>
       Instead of making a tar archive from the local repository, retrieve a tar archive from a remote repository.

命令应该最终如下所示:

$ git archive --remote=https://kave@dndigital.git.cloudforge.com/myoproject.git master

然而,如果您只想提取存储库,则可以使用git clone--depth参数进行浅克隆:

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

所以你有像这样的东西:

$ git clone --depth=1 https://kave@dndigital.git.cloudforge.com/myoproject.git

如何让 git clone --depth=1 拉取特定标签而不是主分支? - robru
7
我认为这个问题值得作为一个独立的问题来提出。但是在阅读关于 git help clone 中的 --[no-]single-branch 后,你可以尝试用类似 git clone --depth=1 --single-branch --branch TARGET_BRANCH REMOTE_URL 的命令来解决问题。谢谢,我以前从未考虑过这点 :) - mgarciaisaia
7
无法从Github归档:您似乎正在使用ssh克隆git:// URL。您可以查阅此文章了解更多详细信息。 - Cloud
3
如果你在尝试从Github通过HTTP下载存档时遇到错误“fatal: operation not supported by protocol”,那么解决方法与@SiminJie提供的文章相同:Github提供了tarball下载服务,所以请使用该服务。 - Guss

1

另一种选项,专门针对GitHub,是github-backup。它有捕获GitHub特定功能(如问题、维基等)的选项。以下是我最近使用的命令行示例,用于存档其他人的存储库:

github-backup --all --pull-details --prefer-ssh --repository REPO REPO-OWNER -u mhucka

在上述命令中,REPO-OWNER代表目标代码库的所有者,而REPO则是代码库名称。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接