git - 如何将特定文件从 Azure Repos 复制到 unix 计算机

标签 git azure-devops wget azure-repos

我在 Azure DevOps 中有一个项目。我想将项目的 Git 存储库中的特定文件复制到我的 unix 盒子中。我想使用命令行来实现这一点。

我尝试了以下命令

  wget -O /unix/path/to/save/file.txt "https://tfs-glo-org.visualstudio.com/team/_git/projectName?path=/fileTobeCopied&version=GBbranch"

它成功地将文件复制到 unix 盒子,但它保存的不仅仅是我想要的文件,而是整个 html 页面。

最佳答案

这绝非易事。原始下载网址有点复杂:

 GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}
     /items?path={path}&scopePath={scopePath}&recursionLevel={recursionLevel}
     &includeContentMetadata={includeContentMetadata}&latestProcessedChange={latestProcessedChange}
     &download={download}&$format={$format}&versionDescriptor.versionOptions={versionDescriptor.versionOptions}
     &versionDescriptor.version={versionDescriptor.version}&versionDescriptor.versionType={versionDescriptor.versionType}
     &includeContent={includeContent}&resolveLfs={resolveLfs}&api-version=5.1

这里对您来说最重要的是设置&download=true。获取这些值的最简单方法是从 UI 下载文件并检查下载 url:

enter image description here

您可以从浏览器的下载页面获取完整的 URL:

enter image description here

full docs for the request format can be found here .

为了成功下载,您还需要传入身份验证 token 或个人访问 token 。 security parts are explained here .

最简单的选项 would be to use a Personal Access Token :

 wget --user . --password {PAT} https://dev.azure.com/....

如果未传入凭据,Azure DevOps 将发送错误页面内容。

关于git - 如何将特定文件从 Azure Repos 复制到 unix 计算机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57525966/

相关文章:

python - 如何使用 PyGithub 创建新的存储库

azure-devops - 使用 VSTS 发布管理,如何修改每个环境的 Azure Web 应用程序的配置?

azure - 无法运行Azure管道 "A task is missing. The pipeline references a task called '缓存'

给定 wget 命令的 Python 等效项

git:补丁不适用

git - 当我需要其他分支的一些代码时如何为功能创建分支(未 merge 到开发分支中)

git - 如何制作一个镜像上游存储库的本地 git 存储库?

azure - 是否有一种服务连接类型和相应的任务可以方便Graph API调用?

ssh - 使用 wget 从 IEEExplore 下载论文

linux - 使用 xargs 和两个参数并行下载