【问题标题】:Get commits of an item in one branch with TFS REST API使用 TFS REST API 在一个分支中获取项目的提交
【发布时间】:2016-06-14 07:14:40
【问题描述】:

我正在尝试使用 Team Service REST API (https://www.visualstudio.com/en-us/docs/integrate/api/git/commits) 在我的 git 存储库的一个特定分支中获取一个特定项目的历史记录。

我的存储库中有这个结构。

Repository1 -- Branch1 -- Item1 -- Item2 -- Branch2 -- Item1 -- Item3

如何在 Branch1 中仅获取 Item1 的提交?

我已尝试发帖:https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/commitsBatch?api-version=1.0

使用 JSON:

{ "itemVersion": { "versionType": "branch", "version": "Branch1" } }

但这给了我整个分支的提交。我如何才能获得该特定分支中该项目的提交?

【问题讨论】:

    标签: git rest tfs azure-devops tfs-2015


    【解决方案1】:

    实际上可以使用 commitsBatch 完全做到这一点。您不必获取所有分支和所有提交并进行比较...

    你做一个 POST 到

    https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/commitsBatch?api-version=1.0

    JSON 字符串是:

     {
       "itemPath":
         "/Folder1/Folder2/item1.extention",
       "$top":250
       "itemVersion": {
         "versionType": "branch",
         "version": "Branch1"
       }
    }
    

    【讨论】:

      【解决方案2】:

      目前还没有任何直接的方法可以通过 Rest API 获得此功能,您可以在 VSTS User Voice 上提交功能请求。

      实现这一点的另一种方法是获取指定分支中的所有提交并获取指定项的所有提交,然后列出两种场景中存在的提交。

      【讨论】:

      猜你喜欢
      • 2015-08-09
      • 1970-01-01
      • 2018-04-08
      • 1970-01-01
      • 2019-10-13
      • 2019-11-26
      • 1970-01-01
      • 1970-01-01
      • 2019-02-01
      相关资源
      最近更新 更多