Git 从 Azure DevOps 获取拉取请求

Git fetch Pull Requests from Azure DevOps

我想使用 git 获取托管在 Azure DevOps 中的存储库中的拉取请求列表。

Github has the support。 我们可以将其添加到 .git/config:

[remote "origin"]
  fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

但是当我为 Azure DevOps 尝试相同的方法时,它没有获取任何东西。我还尝试了 git-extras 包中的 git-pr

我猜他们是否有支持,路径可能与 refs/remotes/origin/pr/ 不同。他们有一个 REST API endpoint 来获取拉取请求,但我找不到任何关于做同样的事情使用 git.

对于 Azure DevOps,配置略有不同。您可以将以下内容添加到 .git/config:

[remote "origin"]
        fetch = +refs/pull/*/merge:refs/remotes/origin/pull/*

也可以在没有像这样的事先配置的情况下将拉取请求临时提取到本地分支中:

git fetch origin refs/pull/$ID/merge:$LOCALBRANCH

获取和签出示例(带配置):

$ git fetch origin -v
remote: Azure Repos
remote: Found 1 objects to send. (18 ms)
Unpacking objects: 100% (1/1), done.
From ssh.dev.azure.com:v3/aaaa/bbbb/cccc
 = [up to date]      main              -> origin/main
 = [up to date]      test-branch       -> origin/test-branch
 * [new ref]         refs/pull/1/merge -> origin/pull/1
$ git checkout pull/1
Branch 'pull/1' set up to track remote branch 'pull/1' from 'origin'.
Switched to a new branch 'pull/1'

临时提取和检出示例(无事先配置):

$ git fetch origin refs/pull/1/merge:pull/1
remote: Azure Repos
remote: Found 1 objects to send. (53 ms)
Unpacking objects: 100% (1/1), done.
From ssh.dev.azure.com:v3/aaaa/bbbb/cccc
 * [new ref]         refs/pull/1/merge -> pull/1
$ git checkout pull/1
Switched to branch 'pull/1'