简体   繁体   English

如何使用用户名和密码从私人 gitlab 存储库下载单个原始文件

[英]How to download single raw file from private gitlab repo using username and password

I can clone a private repo with username & password using command below我可以使用下面的命令克隆一个带有用户名和密码的私有仓库

git clone https://some-git-lab-token:someHash@git.xxx.com/foo/bar.git

I'm wondering if it's possible to curl or wget a single raw file from the same repo using the same credential some-git-lab-token:someHash我想知道是否可以使用相同的凭据some-git-lab-token:someHash从同一个 repo curlwget单个原始文件

A sample gitlab raw file url as below一个示例 gitlab 原始文件 url 如下

https://gitlab.com/athos.oc/lodash-has-plugin/-/raw/master/.eslintrc.json

I've tried to curl a single file as below but failed我试图按如下方式卷曲单个文件但失败了

curl https://some-git-lab-token:someHash@git.xxx.com/foo/bar/-/raw/master/testing.js

The result that I got is as below我得到的结果如下

<html><body>You are being <a href="https://git.xxx.com/users/sign_in">redirected</a>.</body></html>

To download a repository file through curl, you need to use the repository files API endpoint .要通过 curl 下载存储库文件,您需要使用存储库文件 API 端点

Using your example https://gitlab.com/athos.oc/lodash-has-plugin/-/raw/master/.eslintrc.json , would turn into:使用您的示例https://gitlab.com/athos.oc/lodash-has-plugin/-/raw/master/.eslintrc.json ,将变成:

https://gitlab.com/api/v4/projects/30349314/repository/files/%2Eeslintrc%2Ejson/raw?ref=master

However, API authentication does not include username and password as an available authentication method, so you would need to use a token (or a session cookie).但是, API 身份验证不包括用户名和密码作为可用的身份验证方法,因此您需要使用令牌(或会话 cookie)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM