下载 GitLab 私有存储库 [英] Download a GitLab private repository

查看:59
本文介绍了下载 GitLab 私有存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 curl 在 GitLab 中下载我的私人存储库.我知道我可以使用 Gitlab API,但由于某种原因,它不起作用.

这可能吗?当我尝试这样做时,它总是返回登录页面.

解决方案

可能的,只需按照以下步骤操作:

  1. 首先,您必须创建一个个人访问令牌":

    1. 转到

    2. 点击创建个人访问令牌"

    3. 页面将重新加载并保存您的新令牌.

    4. 确保将令牌保存在安全的地方,您将无法再次查看.

  2. 既然您有了个人访问令牌",您需要获取项目 ID 才能使用 API:

    1. 转到

    (或者,您可以直接从其网页复制项目 ID)

  3. 现在您可以调用:

     wget -O your_project.tar.gz https://gitlab.com/api/v4/projects/0000000/repository/archive?private_token=XXXXXXXXXXXXXXXXXXXXX

这会将您的项目下载为 .tar.gz 文件.

您可以通过将 &sha=... 参数添加到 url 来获取特定提交/标记的 tarball,例如:rel="nofollowapi/gitlabr.v4/projects/24470128/repository/archive?private_token=XXXXXXXXXXXXX&sha=606e81c69eff27eccbbc59a0546a9439780dff55

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.

Is this possible? When I try to do it this way, it always returns the login page.

解决方案

This is possible, just follow these steps:

  1. First, you have to create a "Personal Access Token":

    1. Go to Your Profile > Settings > Access Tokens.

    2. Enter a name for your "Personal Access Token".

    3. Check "api Access the authenticated user's API"

    4. Click "Create personal access token"

    5. The page will reload and save your new token.

    6. Make sure you save the token somewhere safe, you won't be able to view it again.

  2. Now that you have your "Personal Access Token", you need to get your project id to use the API:

    1. Go to https://gitlab.com/api/v4/projects?private_token=XXXXXXXXXXXXXXXXXXXX (replace the Xs with your new token)

    2. Get your project's id from the json.

    (alternatively you can just copy Project ID from it's web page)

  3. Now you can call:

     wget -O your_project.tar.gz https://gitlab.com/api/v4/projects/0000000/repository/archive?private_token=XXXXXXXXXXXXXXXXXXXX
    

And that'll download your project as a .tar.gz file.

Edit: you can get tarball for specific commit/tag by adding &sha=... parameter to url, like: https://gitlab.com/api/v4/projects/24470128/repository/archive?private_token=XXXXXXXXXXXXX&sha=606e81c69eff27eccbbc59a0546a9439780dff55

这篇关于下载 GitLab 私有存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆