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

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

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


当前回答

上面的一些选项的问题是,如果有人在打开PR后推送更多的提交,他们就不会给你最新的版本。 对我来说,最有效的方法是-进入PR,按下“提交”,滚动到底部查看最近的提交哈希 然后简单地使用git签出,即。

Git checkout <commit number>

在上面的例子中

git 结帐 0ba1a50

其他回答

你可以使用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

虽然这个线程上的大多数答案都可以工作,但我更喜欢在新的分支中获取一个pull请求,并对旧的提交进行软重置(将PR更改移动到staging区域),这允许我测试以及查看我的IDE中的差异。

git fetch origin pull/<PR-id>/head:<BRANCH_NAME>
git checkout BRANCH_NAME

然后对旧的提交进行软重置(参见使用git log的提交列表)

git reset --soft <hash_of_old_commit>

e.g

git fetch origin pull/65/head:test-branch 
git checkout test-branch
git log # press 'q' to exit
git reset --soft 7d7fe166cd878ed70c559c4e98faf2323532

运行上述命令将提取PR的更改,并将它们显示在您的IDE版本中,它们不会被提交,您可以在登台区域中看到差异(就像这些更改是在本地进行的一样)。

参考:Github文档参考

有一种使用git-cli的简单方法

gh pr checkout {<number> | <url> | <branch>}

参考:https://cli.github.com/manual/gh_pr_checkout

对于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

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

我正在使用hub,一个来自github的工具:https://github.com/github/hub

使用hub在本地检出一个pull请求有点容易:

hub checkout https://github.com/owner/repo/pull/1234
or
hub pr checkout 1234