AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 852894
Accepted
Brad
Brad
Asked: 2017-05-30 13:13:36 +0800 CST2017-05-30 13:13:36 +0800 CST 2017-05-30 13:13:36 +0800 CST

从 powershell 的 bitbucket (git) 获取文件

  • 772

我需要使用 powershell 从 bitbucket (git) 中获取单个文件。使事情复杂化我需要通过 http/https 执行此操作,因为我正在运行 powershell 的系统没有直接的互联网访问权限(因此 ssh 不是一个选项)。我该怎么做?

我想也许我可以使用 Invoke-WebRequest 并访问原始 URL 来获取它。例如:https ://bitbucket.org/company/project/raw/HEAD/some/special/file.txt

但似乎访问您必须进行身份验证。我已尝试设置身份验证,但无法正常工作。

我想接下来我可以使用 git archive 从 git 中提取它: git archive --remote=git://bitbucket.org/Company/project.git HEAD:some/path/file.txt 但这似乎也没有工作。

那么我怎样才能得到一个文件。我不想只做 git clone 因为我必须在 repo 中拉下(并存储)价值 500MB 的其他我不关心的文件,这是一个问题,原因有两个

1) I have to have space to store all that data (at least temporarily)
2) Unless I want to tie up that storage permanently I have to re-download it each time I need the file. 

我需要的文件是 10KB,所以为一个 10kb 的文件占用 500MB 似乎很荒谬。

答案是什么?必须有一种方法可以让 Invoke-WebRequest 正确验证或只下载单个文件?任何 git 大师都可以 - 特别是具有 powershell/windows 背景的帮助吗?

谢谢!布拉德

powershell
  • 1 1 个回答
  • 6008 Views

1 个回答

  • Voted
  1. Best Answer
    Ryan Bolger
    2017-05-30T13:48:26+08:002017-05-30T13:48:26+08:00

    BitBucket 似乎有一个非常标准的 REST API,您可以使用Invoke-WebRequest或Invoke-RestMethod。

    以下是他们文档的一些链接:Authentication and GET raw content。这些文档页面的要点是它们支持基本身份验证和对原始文件内容的 GET 请求。因此,从您的示例中,您需要执行以下操作:

    # create a credential variable for your account
    $cred = Get-Credential
    
    # modify the base URL to hit the API endpoint instead of the standard web endpoint, pass the credentials with the request, and send the output to a file
    Invoke-RestMethod -Credential $cred -Uri https://api.bitbucket.org/1.0/repositories/company/project/raw/HEAD/some/special/file.txt -OutFile .\file.txt
    
    • 3

相关问题

  • 资源锁和电源外壳

  • 脚本 - 如何断开远程桌面会话?

  • 如何限制向通讯组发送到外部地址?

  • Powershell对值与数组的作用不同?

  • Windows Powershell Vim 键绑定

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve