git gitlab 通过命令行获取特定分支的 tar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22691197/
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
gitlab get tar of a specific branch via command line
提问by Chris Maes
I'm using gitlab. When I go into the interface, on each branch I can download the source code as a zip, tar or whatsoever.
我正在使用 gitlab。当我进入界面时,我可以在每个分支上下载 zip、tar 或任何形式的源代码。
I am making rpm spec files for which I would need the possibility to download the tar ball using command line. since I added my rsa key i can do git clone without problems:
我正在制作 rpm 规范文件,我需要可以使用命令行下载 tar 球。因为我添加了我的 rsa 密钥,所以我可以毫无问题地执行 git clone:
git clone http://gitlab/group/project.git
Cloning into 'project'...
remote: Counting objects: 1885, done.
remote: Compressing objects: 100% (826/826), done.
remote: Total 1885 (delta 1194), reused 1496 (delta 954)
Receiving objects: 100% (1885/1885), 1.30 MiB | 0 bytes/s, done.
Resolving deltas: 100% (1194/1194), done.
Checking connectivity... done
However doing
然而做
wget http://gitlab/group/project/repository/archive.zip
gets me these errors:
给我这些错误:
Resolving gitlab (gitlab)... 10.1.253.75
Connecting to gitlab (gitlab)|10.1.253.75|:80... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Authorization failed.
采纳答案by VonC
Since GitLab 6.2and issue 5253, it should be:
由于GitLab 6.2和issue 5253,它应该是:
GET /projects/:id/repository/archive
But that seems for internal use only, since you cannot know the id of a project as a user (only its name).
但这似乎仅供内部使用,因为您无法作为用户知道项目的 id(仅其名称)。
Don't forget, as shown in ability.rb
, that downloading an archive is linked to a permission. Make sure you have that "download_code
" permission set for your project.
不要忘记,因为shown in ability.rb
下载档案与权限相关联。确保您download_code
为您的项目设置了“ ”权限。
Here, it must be a permission issue, because, for instance:
在这里,它一定是一个权限问题,因为,例如:
wget http://demo.gitlab.com/gitlab/gitlab-recipes/repository/archive.zip
That works just fine, and get the content of that project without any issue.
这工作得很好,并且可以毫无问题地获取该项目的内容。
However, as the OP Chris Maescommentsand mentions in issue 6645, as as illustrated by app/models/ability.rb
:
但是,正如OP Chris Maes在issue 6645 中评论和提及的那样,如图所示:app/models/ability.rb
if project && project.public?
... that "dowload_code
" feature is onlyfor public projects.
...“ dowload_code
”功能仅适用于公共项目。
回答by laze
For me the private_token
and the sha
or ref
parameters does not worked together. So, I changed the way, and I tell my private token via a header parameter to the Gitlab API, like this:
对我来说,private_token
和sha
或ref
参数不能一起工作。所以,我改变了方式,我通过一个 header 参数告诉我的私有令牌给 Gitlab API,就像这样:
wget http://{{your_host}}/api/v3/projects/{{project_id}}/repository/archive?sha={{commit_sha}} --header='PRIVATE-TOKEN: {{private_token}}'
回答by user2688588
try this
尝试这个
curl http://$yourhost:$port/$yourgroup/$yourrepo/repository/archive.zip\?ref\=$yourbranch\&\private_token\=$yourtoken -o newpackage.zip
回答by Brett Porter
I didn't want to have to get the project ID first, but rather use group|org and repository name similar to the Github HTTP API. This is what works for me on 11.9.0-ce.0
我不想首先获得项目 ID,而是使用类似于 Github HTTP API 的 group|org 和存储库名称。这在 11.9.0-ce.0 上对我有用
Private/Internal Project
私人/内部项目
curl "https://gitlab.yourdomain.com/api/v4/projects/engineering%2Faccount-service/repository/archive?sha=some-branch-name" \
-H "Private-Token: $GITLAB_TOKEN" \
-o /tmp/account-service-branch-name.tar.gz
Public Project
公共项目
curl "https://gitlab.yourdomain.com/engineering/account-service/repository/archive.tar.gz?ref=some-branch-name" \
-o /tmp/account-service-branch-name.tar.gz
In this example
在这个例子中
- "group" is
engineering
- "repository" is
account-service
- “组”是
engineering
- “存储库”是
account-service
Don't forget the %2F
between group
and repo
不要忘记%2F
之间group
和repo
Hope it helps anyone
希望它可以帮助任何人