如何检查更改类型是否合并”或“分支”检索git时通过Azure DevOps REST API变化

发布于 2025-01-31 12:21:36 字数 3619 浏览 4 评论 0原文

我正在从Azure DevOps REST API中获取GIT变化,并想区分特定的提交是否是合并/分支操作。默认的更改型为:添加,编辑,删除,我找不到任何“合并”或“分支”的引用。

是否有内置的方法可以实现这一目标

? git/commits/get?view = vsts-rest-tfs-4.1“ rel =“ nofollow noreferrer”> from官方文档: 获取https:// {instance}/{collection}/_apis/git/repositories/{repositorityId}/consits/{commitid}?api-version = 4.1 响应就像是:

{
  "parents": [],
  "treeId": "7fa1a3523ffef51c525ea476bffff7d648b8cb3d",
  "push": {
    "pushedBy": {
      "id": "8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d",
      "displayName": "Chuck Reinhart",
      "uniqueName": "[email protected]",
      "url": "https://fabrikam:8080/tfs/_apis/Identities/8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d",
      "imageUrl": "https://fabrikam:8080/tfs/_api/_common/identityImage?id=8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d"
    },
    "pushId": 1,
    "date": "2014-01-29T23:33:15.2434002Z"
  },
  "commitId": "be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4",
  "author": {
    "name": "Chuck Reinhart",
    "email": "[email protected]",
    "date": "2014-01-29T23:32:09Z"
  },
  "committer": {
    "name": "Chuck Reinhart",
    "email": "[email protected]",
    "date": "2014-01-29T23:32:09Z"
  },
  "comment": "First cut\n",
  "changeCounts": {
    "Add": 2
  },
  "changes": [
    {
      "item": {
        "gitObjectType": "blob",
        "path": "/.gitattributes",
        "url": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/items/.gitattributes?versionType=Commit"
      },
      "changeType": "add"
    },
    {
      "item": {
        "gitObjectType": "blob",
        "path": "/.gitignore",
        "url": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/items/.gitignore?versionType=Commit"
      },
      "changeType": "add"
    }
  ],
  "url": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/commits/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4",
  "remoteUrl": "https://fabrikam:8080/tfs/_git/Fabrikam-Fiber-Git/commit/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4",
  "_links": {
    "self": {
      "href": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/commits/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4"
    },
    "repository": {
      "href": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249"
    },
    "changes": {
      "href": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/commits/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4/changes"
    },
    "web": {
      "href": "https://fabrikam:8080/tfs/_git/Fabrikam-Fiber-Git/commit/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4"
    },
    "tree": {
      "href": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/trees/7fa1a3523ffef51c525ea476bffff7d648b8cb3d"
    }
  }
}

如果没有内置的方法来实现这一目标,那么parent是否应该用作指导?就像是空的一样,它是一个“分支”操作,如果其中有两个条目是“合并”?

更新1

我可以在上面引用的文档中看到Mergebranch ChangeTypes,但是当我查询合并的更改时,仅包含编辑add

I am fetching Git changes from Azure DevOps REST Api and want to distinguish if a specific commit was a merge/branch operation. The default changeTypes are: add, edit, delete and I couldn't find any reference for "merge" or "branch".

Is there a built in way to achieve this?

My query uses the following syntax from the official doc:
GET https://{instance}/{collection}/_apis/git/repositories/{repositoryId}/commits/{commitId}?api-version=4.1
And the response is like:

{
  "parents": [],
  "treeId": "7fa1a3523ffef51c525ea476bffff7d648b8cb3d",
  "push": {
    "pushedBy": {
      "id": "8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d",
      "displayName": "Chuck Reinhart",
      "uniqueName": "[email protected]",
      "url": "https://fabrikam:8080/tfs/_apis/Identities/8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d",
      "imageUrl": "https://fabrikam:8080/tfs/_api/_common/identityImage?id=8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d"
    },
    "pushId": 1,
    "date": "2014-01-29T23:33:15.2434002Z"
  },
  "commitId": "be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4",
  "author": {
    "name": "Chuck Reinhart",
    "email": "[email protected]",
    "date": "2014-01-29T23:32:09Z"
  },
  "committer": {
    "name": "Chuck Reinhart",
    "email": "[email protected]",
    "date": "2014-01-29T23:32:09Z"
  },
  "comment": "First cut\n",
  "changeCounts": {
    "Add": 2
  },
  "changes": [
    {
      "item": {
        "gitObjectType": "blob",
        "path": "/.gitattributes",
        "url": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/items/.gitattributes?versionType=Commit"
      },
      "changeType": "add"
    },
    {
      "item": {
        "gitObjectType": "blob",
        "path": "/.gitignore",
        "url": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/items/.gitignore?versionType=Commit"
      },
      "changeType": "add"
    }
  ],
  "url": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/commits/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4",
  "remoteUrl": "https://fabrikam:8080/tfs/_git/Fabrikam-Fiber-Git/commit/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4",
  "_links": {
    "self": {
      "href": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/commits/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4"
    },
    "repository": {
      "href": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249"
    },
    "changes": {
      "href": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/commits/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4/changes"
    },
    "web": {
      "href": "https://fabrikam:8080/tfs/_git/Fabrikam-Fiber-Git/commit/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4"
    },
    "tree": {
      "href": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/trees/7fa1a3523ffef51c525ea476bffff7d648b8cb3d"
    }
  }
}

If there is no built in way to achieve this, should the parent be used as a guidance? Like if it is empty it is a 'branch' operation and if there is two entries in it it is a 'merge'?

Update 1

I can see in the documentation referenced above that there are merge and branch changeTypes, but when I query a change that was merged the result only contains edit or add.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别闹i 2025-02-07 12:21:36

您将必须使用父母收藏来确定是否合并。由于正常提交只有1个父母,因此超过1表示合并。

从git文档在这里

提交对象可能有许多父母。正好有一个父母,这是一个普通的提交。拥有多个父母会使该提交在几行历史之间合并。初始(根)提交没有父母。

You will have to use the parents collection to determine whether it was a merge. Since normal commits just have 1 parent, more than 1 indicates a merge.

From the git documentation here

A commit object may have any number of parents. With exactly one parent, it is an ordinary commit. Having more than one parent makes the commit a merge between several lines of history. Initial (root) commits have no parents.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文