我知道How can I check out a GitHub pull request?
虽然向.git/config
添加fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
确实允许获取和检出,但拉取操作失败:
[remote "origin"]
url = https://github.com/the/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
Fetch和checkout工作正常:
$ git fetch origin
..。都很好
$ git checkout -b "pr-123" origin/pr/123
Branch pr-123 set up to track remote branch pr/123 from origin.
Switched to a new branch 'pr-123'
..。成功,拿到代码了!
但是拉取失败了:
$ git pull
Your configuration specifies to merge with the ref 'refs/heads/pr/123'
from the remote, but no such ref was fetched.
..。失败。
我可以手动指定ref:
$ git pull origin refs/pull/123/head
这是可行的。但是,我如何配置配置文件,以便:
在不手动指定远程
的情况下,远程提取和签出操作仍然有效,远程拉入操作也有效
我发现如果我编辑配置文件并更改:
[branch "pr-123"]
remote = origin
merge = refs/heads/pr/123
至:
[branch "pr-123"]
remote = origin
merge = refs/pull/123/head # <-- here is the change
..。那么git pull
就可以正常工作了。如何在不手动编辑每个拉取请求的配置文件的情况下实现这一点?
发布于 2016-11-27 19:35:54
我想我找到了一个解决方案,而且非常简单:fetch = +refs...
中的行的顺序很重要!
我改变了:
[remote "origin"]
url = https://github.com/the/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
至:
[remote "origin"]
url = https://github.com/the/repo.git
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
fetch = +refs/heads/*:refs/remotes/origin/*
(交换了最后两行)
现在一切都正常了(fetch
、checkout
、pull
)。
我仍然在等待看到这个配置的一些(非)预期的问题,但到目前为止还不错……
发布于 2016-11-20 12:25:03
您只获取了分支,而不是拉取请求。将以下内容添加到您的配置中:
fetch = +refs/pull/*/head:refs/pulls/origin/pr/*
之后,您可以结帐一个指向PR远程引用的分支:
git checkout -b "pr-123" pulls/origin/pr/123
通常,如果您是从遥控器获取引用,则可以查看引用,因此请查看git fetch
命令输出并找到PR的引用名称。这就是您应该放在checkout
命令中的内容。您应该会看到类似这样的内容:
[new ref] refs/pull/123/head -> refs/pulls/origin/pr/123
请注意,您可以用pulls
部件替换任何自定义前缀。现在,您可以创建一个分支并将其指向pulls/origin/pr/123
,这相当于refs/pulls/origin/pr/123
(请参见git refspec doc)。
发布于 2016-11-20 15:26:41
从fetch规范中不可能明确地发现远程引用refs/remotes/origin/pr/123
跟踪origin:refs/pull/123/head
,因为origin:refs/heads/pr/123
也是可能的。为了帮助它,您可以使用不同的远程名称,例如:
[remote "origin-pr"]
url = <same as for origin>
fetch = +refs/pull/*/head:refs/remotes/origin-pr/pr/*
然后,具有显式分支名称的git checkout (应该在GUI中可用)将能够创建正确的跟踪引用:
$ git checkout -b pr/123 origin-pr/pr/123
[branch "pr/123"]
remote = origin-pr
merge = refs/pull/123/head
然而,看起来不可能让简单的git checkout br/123
工作:
$ git checkout pr/123
error: pathspec 'pr/123' did not match any file(s) known to git.
https://stackoverflow.com/questions/40662771
复制相似问题