【问题标题】:How to copy a particular file from Azure Repos to unix machine如何将特定文件从 Azure Repos 复制到 unix 机器
【发布时间】:2019-12-22 20:33:54
【问题描述】:

我在 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 页面。

【问题讨论】:

  • 更新的 TFS -> Azure Repos 给定您的示例 URL 引用 .visualstudio.com。

标签: git azure-devops wget azure-repos


【解决方案1】:

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

 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:

您可以从浏览器的“下载”页面获取完整网址:

full docs for the request format can be found here。

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

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

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

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

【讨论】:

  • 这可能只是我们的管理员设置,但我下载了一个 html 文档,而不是我所针对的 .sh。这是你遇到过的事情吗?
  • 当您获得 HTML 时,很可能是访问被拒绝或文件未找到。我的猜测是令牌没有正确的权限,是否已过期或不适用于正确的组织。
【解决方案2】:

文件存储在 Git 源代码控制中是有原因的。 不要以您尝试的方式下载。

使用命令行git clone 存储库并找到您要选择的文件。

https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-clone

您始终可以定位特定的tag 或commit。

【讨论】:

  • 只需要一个文件时为什么要克隆?如果我只想在 linux 服务器上使用脚本,我会更喜欢下载单个文件。
  • 更正:当你只想要一个文件时为什么要克隆是个问题。如果您只想在服务器上使用像脚本这样的文件,那么很容易想要下载单个文件。但是您最终可能会选择错误的文件版本。因此克隆更好
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-01
  • 1970-01-01
  • 2020-04-12
  • 1970-01-01
  • 2016-09-27
相关资源
最近更新 更多