【问题标题】:How do I find commit hash of a file using GitLab API?如何使用 GitLab API 找到文件的提交哈希?
【发布时间】:2016-01-28 19:34:16
【问题描述】:

我试图找出我的存储库中文件的提交哈希是什么。不同的文件被不同的提交修改。

我在 GitLab 网络界面上看到了以下信息:

但是如何使用 GitLab API 获取这些信息?我试着做:

GET /projects/:id/repository/files

https://gitlab_server/api/v3/projects/1234/repository/files?file_path=test/file2.tconf&ref=master

但是响应中的 commit_id 匹配 HEAD 的哈希 0f05a8e4bf45942b1189fce923184129821845f1,而不是上面屏幕截图中看到的。

{
  "file_name": "file2.tconf",
  "file_path": "test/file2.tconf",
  "size"     : 44,
  "encoding" : "base64",
  "content"  : "...",
  "ref"      : "master",
  "blob_id"  : "50450759d2b0694b044ed3d7eaf93c2c98dacbba",
  "commit_id": "0f05a8e4bf45942b1189fce923184129821845f1"
}

有什么线索吗?

【问题讨论】:

    标签: git api hash gitlab git-commit


    【解决方案1】:

    last-commit-id 现在存在,并提供了您所要求的内容:修改该特定文件的最后一次提交。

    GitLab's get-file-from-repository API

    【讨论】:

      【解决方案2】:

      get-a-single-commit 我刚刚为我的项目自己测试了它,用它来获取有关上次提交的信息,我想您现在可以轻松获得您想要的东西。

      GitLab's get-a-single-commit

      GET /projects/:id/repository/commits/:sha

      curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/repository/commits/master"
      

      【讨论】:

        猜你喜欢
        • 2020-02-27
        • 1970-01-01
        • 2018-01-31
        • 1970-01-01
        • 2021-03-13
        • 1970-01-01
        • 2011-10-07
        • 2023-03-27
        • 1970-01-01
        相关资源
        最近更新 更多