从PowerShell中的bitbucket(git)获取文件

我需要使用PowerShell从bitbucket(git)抓取一个文件。 复杂的事情,我需要这样做通过HTTP / HTTPS,因为我运行PowerShell的系统没有直接的互联网访问(因此SSH不是一个选项)。 我怎么能这样做?

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

但它似乎访问,你必须authentication。 我试过设置身份validation,但我无法得到它的工作。

我想接下来我可以从git使用git归档:git archive –remote = git://bitbucket.org/Company/project.git HEAD:some / path / file.txt但是这似乎也不工作。

那么我怎样才能得到一个单一的文件。 我不想只是做混帐克隆,因为那么我必须拉下(和存储)价值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正确地进行身份validation,或者只是下载一个文件? 任何git大师 – 特别是与PowerShell / Windows的背景可以帮助吗?

谢谢! 布拉德

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

这里有一些指向他们的文档的链接: authentication和GET原始内容 。 这些文档页面的要点是它们支持原始文件内容的基本authentication和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