在 Azure Git 中运行“git archive”会给出错误消息

问题描述

我正在尝试从 Azure Git 存储库中提取单个文件

但是如果我运行这个: git archive --remote="ssh.dev.azure.com:v3/[organization]/[project]/[repo]" master myfile

它返回一个错误

remote: Could not find a Command Extension for Command:git-upload-archive
fatal: the remote end hung up unexpectedly

这在 Linux 和 Windows 中都会发生。

另一方面,请注意这些工作正常:

git clone "ssh.dev.azure.com:v3/[organization]/[project]/[repo]"

git ls-remote "ssh.dev.azure.com:v3/[organization]/[project]/[repo]"

解决方法

考虑:

  • 远程端 (Azure) 不支持 git archive
  • git clone 有效

显而易见的解决方法是先执行 git clone --no-checkout,然后只执行您需要的文件的 git restore
sparse checkout

git clone --filter=blob:none --sparse /url/repo
cd repo
git sparse-checkout init --cone

## or

git clone --filter=sparse:oid=shiny-app/.gitfilterspec` /url/repo
cd repo

# with .gitfilterspec including the file you need

,

我能够使用这种方法从文件中提取数据:

curl -u ":[Personal Access Token]" "https://dev.azure.com/[organization]/[project]/_apis/sourceProviders/TfsGit/filecontents?repository=[repo]&path=[filepath]&commitOrBranch=[branch]&api-version=5.0-preview.1"