git 归档来自远程的特定哈希

Fer*_*ins 7 git hash commit bitbucket archive

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

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

但我越来越

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
Run Code Online (Sandbox Code Playgroud)

所以我读到我可以使用另一个上传存档,如下所示:

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

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

Von*_*onC 0

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

git clone <url> --depth=1 --branch <branch_name> -- <folder_name>
Run Code Online (Sandbox Code Playgroud)

然后做好存档。

但出于安全原因,您无法直接获取或克隆特定的提交