如何从GitLab下载单个文件? [英] How to download a single file from GitLab?
问题描述
我知道可以提取然后使用带有/to/file路径的checkout下载该特定文件.
I know it is possible to fetch then use checkout with the path/to/file to download that specific file.
我的问题是我每天有1 MB的数据上限,并且git fetch无论如何都将下载所有数据,即使它直到使用git checkout才将它们保存到磁盘上.我仍然使用我的数据
My issue is that I have a 1 MB data cap per day and git fetch will download all the data anyway even if it does not save them to disc until I use git checkout. I still used my data
我对git fetch/checkout如何正确的理解吗?有没有一种方法可以下载特定文件,而仅在进行下载之前先查看是否有新版本.
Is my understanding of how git fetch/checkout correct? is there a way to download a specific file only to see if there is a new version before proceeding with the download.
推荐答案
Gitlab为此提供了一个REST API.
Gitlab has a rest API for that.
您可以使用curl从存储库中获取文件:
You can GET a file from repository with curl:
curl https://gitlab.com/api/v4/projects/:id/repository/files/:filename\?ref\=:ref
例如:
curl https://gitlab.com/api/v4/projects/12949323/repository/files/.gitignore\?ref\=master
如果您的存储库不公开,则还需要通过添加-标头'Private-Token:< your_access_token>'
来提供访问令牌.
If your repository isn't public you also need to provide an access token by adding --header 'Private-Token: <your_access_token>'
.
You can check how to find repository api id here.
还有一个使用此api的 python库.
There is also a python library that uses this api.
请注意,这是GitLab特定的解决方案,不适用于其他主机.
Note that this is GitLab specific solution and won't work for other hostings.
这篇关于如何从GitLab下载单个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!