如何在 azure devops 中知道分叉存储库的源存储库?

How to know the source repository of a forked repository, in azure devops?

我正在我的 Azure DevOps 项目中的一个存储库中工作,它是从其他一些 azure DevOps 项目派生出来的。我想知道来源(完成分叉的原始回购)。

请告诉我如何获取此信息。

我不知道这在 UI 中公开了,但至少有两种其他方法可以获得有关上游(父)存储库的信息

选项 1:使用其余部分 API

https://dev.azure.com/{organization}}/{{project}}/_apis/git/repositories/{{forkname}}?includeParent=true&api-version=6.0GET 请求将在 return 消息中有一个名为 parentRepository 的字段,其中包含有关上游存储库的详细信息

...
"parentRepository": {
        "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "name": "myrepo",
        "isFork": false,
        "url": "https://dev.azure.com/myorg/_apis/git/repositories/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "remoteUrl": "https://myorg@dev.azure.com/myorg/myproject/_git/myproject",
        "sshUrl": "git@ssh.dev.azure.com:v3/myorg/myproject/myproject",
        "project": {
            "id": "yyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy",
            "name": "myproject",
            "url": "https://dev.azure.com/myorg/_apis/projects/zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz",
            "state": "unchanged",
            "visibility": "unchanged",
            "lastUpdateTime": "0001-01-01T00:00:00"
        },
        "collection": null
    }
...

选项 2:克隆存储库并检查服务器消息

当您从 Azure DevOps Repos 克隆分叉的 Repo 时,服务器会发送以下消息(使用标准 git 命令行客户端可见)

Cloning into 'myfork'...
Password for 'https://danielorn@dev.azure.com':
remote: Azure Repos
remote: This repository is a fork. Learn more at https://aka.ms/whatisafork.
remote: To add its upstream as a remote, run:
remote: git remote add upstream https://myorg@dev.azure.com/myorg/myproject/_git/myrepo
remote:
remote: Found 9 objects to send. (67 ms)
Unpacking objects: 100% (9/9), 1.78 KiB | 6.00 KiB/s, done.

从这条消息中,您可以通过查看建议的上游远程找到原始存储库:

git remote add upstream https://myorg@dev.azure.com/myorg/myproject/_git/myrepo

换句话说,fork的上游repo叫做myrepo,位于myorganization里面的myproject