如何使用gitlab API从存储库提交中检索原始文件内容?

时间:2019-01-24 04:36:56

标签: git gitlab gitlab-api

我们可以通过以下方式获取存储库提交列表:

GET /projects/:id/repository/commits?path=:thefilename

我们可以通过blob ID获取原始文件内容:

GET /projects/:id/repository/blobs/:sha/raw

但是,第一个api不会返回每个存储库提交的blob ID,并且没有已知的api可以使用提交ID来检索原始文件内容。我需要从过去的存储库提交中检索原始文件内容,而不仅仅是最新的提交。

1 个答案:

答案 0 :(得分:1)

这实际上不是事实。该API直接支持从任意引用获取文件,因为git直接支持:

  

GET /projects/:id/repository/files/:file_path/raw

     
      
  • file_path(必填)-网址编码的新文件的完整路径。例如lib%2Fclass%2Erb
  •   
  • ref(必填)-分支的名称,标签或提交
  •   

例如:

  

curl --request GET --header'PRIVATE-TOKEN:''https://gitlab.example.com/api/v4/projects/13083/repository/files/app%2Fmodels%2Fkey%2Erb/raw?ref=master'

Read More at Get raw file from repository

相关问题