git 下载 GitLab 私有存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24463229/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Download a GitLab private repository
提问by user3785137
I want to use curl
to download my private repo in GitLab. I know I can use the Gitlab API, but for some reason, It doesn't work.
我想用来curl
在 GitLab 中下载我的私人仓库。我知道我可以使用 Gitlab API,但由于某种原因,它不起作用。
Is this possible? When I try to do it this way, it always returns the login page.
这可能吗?当我尝试这样做时,它总是返回登录页面。
回答by pdeschen
This ispossible, just follow these steps:
这是可能的,只需按照以下步骤操作:
First, you have to create a "Personal Access Token":
- Go to Your Profile > Settings > Access Tokens.
- Enter a name for your "Personal Access Token".
Check "apiAccess the authenticated user's API"
Click "Create personal access token"
- The page will reload and save your new token.
Make sure you save the token somewhere safe, you won't be able to view it again.
Now that you have your "Personal Access Token", you need to get your project id to use the API:
- Go to https://gitlab.com/api/v3/projects?private_token=XXXXXXXXXXXXXXXXXXXX(replace the Xs with your new token)
Get your project's id from the json.
Now you can call:
wget -O your_project.tar.gz https://gitlab.com/api/v3/projects/0000000/repository/archive?private_token=XXXXXXXXXXXXXXXXXXXX
首先,您必须创建一个“个人访问令牌”:
- 转到您的个人资料 > 设置 > 访问令牌。
- 输入“个人访问令牌”的名称。
勾选“ api访问认证用户的API”
点击“创建个人访问令牌”
- 该页面将重新加载并保存您的新令牌。
确保将令牌保存在安全的地方,您将无法再次查看它。
现在您有了“个人访问令牌”,您需要获取项目 ID 才能使用 API:
- 转到https://gitlab.com/api/v3/projects?private_token=XXXXXXXXXXXXXXXXXXXXXX(将 X 替换为您的新令牌)
从 json 中获取项目的 id。
现在你可以调用:
wget -O your_project.tar.gz https://gitlab.com/api/v3/projects/0000000/repository/archive?private_token=XXXXXXXXXXXXXXXXXXXXX
And that'll download your project as a .tar.gz
file.
这会将您的项目作为.tar.gz
文件下载。
回答by Michael Wyraz
You can use the private token that is yours (found in "profile settings") to access any resource. Just browse to the repository file you want to download, copy the "raw" file link and append ?private_token=...
您可以使用属于您的私有令牌(在“配置文件设置”中找到)来访问任何资源。只需浏览到您要下载的存储库文件,复制“原始”文件链接并附加 ?private_token=...
Example:
例子:
curl https://git.local/user1/myrepo/raw/master/myfile.txt?private_token=ahgiretherghaeoi
回答by VonC
You can, but you need to authenticate yourself (as in "Gitlab API: How to generate the private token")
你可以,但你需要对自己进行身份验证(如“ Gitlab API:如何生成私有令牌”)
curl http://gitlab.server/api/v3/session --data 'login=myUser&password=myPass'
Then with the private token:
然后使用私有令牌:
curl --header "PRIVATE-TOKEN: QVy1PB7sTxfy4pqfZM1U" "http://example.com/api/v3/projects"
Or, in your case, get the repository files:
或者,在您的情况下,获取存储库文件:
GET /projects/:id/repository/files
Or, download directly one file.
或者,直接下载一个文件。
回答by Waddles
If you need to do this in a CI run and your private repo is on the same server, you should be able to use git submodulesto clone other repos at the same time. Using the ${CI_JOB_TOKEN}
is another optionsince GitLab 8.12.
如果您需要在 CI 运行中执行此操作并且您的私有存储库位于同一服务器上,则您应该能够使用git 子模块同时克隆其他存储库。使用${CI_JOB_TOKEN}
是自 GitLab 8.12 以来的另一种选择。
回答by frakman1
Provided you have your own "Personal Access Token" (as described in other answers) you can download an archive of your repository's branch by using the curl
command:
如果您有自己的“个人访问令牌”(如其他答案中所述),您可以使用以下curl
命令下载存储库分支的存档:
curl -k --header "PRIVATE-TOKEN: xxxx" https://gitlab.xxxxx/api/v4/projects/<projectID>/repository/archive?sha=630bc911c1c20283d3980dcb95fd5cb75479bb9c -o myFilename.tar.gz
ProjectID is displayed on the repo's main page. You can obtain the SHA value from the webUI after selecting the branch you want from the pull-down and copying the value on the right for the SHA. See screenshot below:
ProjectID 显示在 repo 的主页上。从下拉列表中选择您想要的分支并复制右侧的值作为 SHA 后,您可以从 webUI 获取 SHA 值。请看下面的截图:
The other way to do this is via wget
like this:
另一种方法是通过wget
这样的:
wget --no-check-certificate -O myFilename.zip --header=PRIVATE-TOKEN:xxxx "https://gitlab.xxxx/api/v4/projects/<projectID>/repository/archive.zip?sha=630bc911c1c20283d3980dcb95fd5cb75479bb9c"
I hope that helps.
我希望这有帮助。