来自远程的特定哈希的 git 存档 [英] git archive from a specific hash from remote

查看:21
本文介绍了来自远程的特定哈希的 git 存档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从一个远程存储库中获取一个目录,但我只想从特定的哈希中获取该文件.如果我使用带有 HEAD 的 git archive 一切正常,但是当我尝试使用特定的哈希时:

git archive -v --format tar --remote=ssh://....myrepo.git agitash afile > output.tgz

但是我得到了

fatal:向客户端发送错误:git upload-archive:归档程序因错误而死亡远程:致命:没有这样的参考:9a9c309远程:git upload-archive:归档程序因错误而死亡

所以我读到我可以像这样使用另一个上传存档:

git archive -v --format tar --remote=ssh:.....myrepo.git --exec="/usr/local/bin/git upload-archive" ahash afile > output.tgz

也没有用.我认为是因为 BitBucket 不支持 https://confluence.atlassian.com/bitbucketserverkb/git-upload-archive-archiver-died-with-error-779171761.html

所以我想知道:还有其他简单的方法可以做到这一点吗?

解决方案

如果该提交被分支引用,您可以直接在正确的提交处进行浅层克隆:

git clone --depth=1 --branch -- <文件夹名称>

然后进行存档.

但出于安全原因,您不能直接获取或克隆特定提交.

I am trying to get one directory from one remote repository but I only want to get that file from a specific hash. If I use git archive with HEAD everything is OK but when I try with a specific hash:

git archive -v --format tar --remote=ssh://....myrepo.git agithash afile > output.tgz

But I'm getting

fatal: sent error to the client: git upload-archive: archiver died with error
remote: fatal: no such ref: 9a9c309
remote: git upload-archive: archiver died with error

So I've read that I could use another upload-archive like this:

git archive -v --format tar --remote=ssh:.....myrepo.git --exec="/usr/local/bin/git upload-archive" ahash afile > output.tgz

It didn't work either. I assume is because BitBucket does not support it as per https://confluence.atlassian.com/bitbucketserverkb/git-upload-archive-archiver-died-with-error-779171761.html

So I wonder: is there another simple way to do this?

解决方案

If that commit is referenced by a branch, You could do a shallow clone directly at the right commit:

git clone <url> --depth=1 --branch <branch_name> -- <folder_name>

And then make an archive.

But you cannot directly get or clone a specific commit, for security reason.

这篇关于来自远程的特定哈希的 git 存档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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