我想检查之前创建的拉请求(通过GitHub web界面创建)。我搜索了一下,发现不同的地方有裁判/拉或裁判/拉/pr

但是当我添加fetch = +refs/pull/*/head:refs/remotes/origin/pr/*到git配置文件并进行git取回时

我哪里做错了?GitHub应该自动创建拉/xyz东西,还是我必须配置一些东西?


当前回答

你可以使用git config命令来写一个新的规则到.git/config来从存储库中获取pull请求:

$ git config --local --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*'

然后就是:

$ git fetch origin
Fetching origin
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 4 (delta 2), reused 4 (delta 2), pack-reused 0
Unpacking objects: 100% (4/4), done.
From https://github.com/container-images/memcached
 * [new ref]         refs/pull/2/head -> origin/pr/2
 * [new ref]         refs/pull/3/head -> origin/pr/3

其他回答

要获取远程PR到本地回购,

git fetch origin pull/$ID/head:$BRANCHNAME

其中$ID是拉请求ID, $BRANCHNAME是你想要创建的新分支的名称。一旦您创建了分支,那么简单

git checkout $BRANCHNAME

例如,让我们想象一下,你想从源主分支签出拉请求#2:

git fetch origin pull/2/head:MASTER

更多信息请参阅官方GitHub文档。

要快速检查本地的PR,请打开它并检查从中创建PR的分支名称。

正如我们在上面的红线中看到的,分支的名称是'CLUPET-173-glrr-apis' 使用下面的命令来快速查看PR/Branch中的代码

git checkout origin/CLUPET-173-glrr-apis

现在这段代码在您的本地将运行为分离头模式。

停止所有PR代码查看,并返回到前一个分支

git switch -

如果你想移动PR(加上你在获取PR后所做的任何新的本地更改)到一个新的本地分支,使用下面的命令

git switch -c myNewLocalBranch

对于Bitbucket,你需要将pull替换为pull-requests。

首先,你可以通过git ls-remote origin命令确认pull request URL样式。

$ git ls-remote origin |grep pull
f3f40f2ca9509368c959b0b13729dc0ae2fbf2ae    refs/pull-requests/1503/from
da4666bd91eabcc6f2c214e0bbd99d543d94767e    refs/pull-requests/1503/merge
...

正如你所看到的,它是refs/pull-requests/1503/from而不是refs/pull/1503/from

然后你可以使用任何答案的命令。

你可以使用git config命令来写一个新的规则到.git/config来从存储库中获取pull请求:

$ git config --local --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*'

然后就是:

$ git fetch origin
Fetching origin
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 4 (delta 2), reused 4 (delta 2), pack-reused 0
Unpacking objects: 100% (4/4), done.
From https://github.com/container-images/memcached
 * [new ref]         refs/pull/2/head -> origin/pr/2
 * [new ref]         refs/pull/3/head -> origin/pr/3

如果你使用Github.com,转到“拉请求”,点击相关的拉请求,然后点击“命令行说明”链接: