我知道如何检查 GitHub 上的 pull request,具体操作请参考此链接。
将fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
添加到.git/config
可以实现 fetch 和 checkout,但是 pull 操作会失败:
[remote "origin"]
url = https://github.com/the/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
获取和检出工作正常:
$ 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.
...失败了。
我可以手动指定参考文献:
$ git pull origin refs/pull/123/head
这个方法是有效的。但是我该如何配置配置文件,以便:
1. 仍然可以使用fetch和checkout命令 2. 后续的pull操作可以在不手动指定远程引用的情况下正常工作?
我发现如果我编辑配置文件并更改以下内容:
[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
就可以正常工作。如何在不手动编辑每个拉取请求的配置文件的情况下实现这一点?
pull
没有起作用。我已经在问题中添加了配置文件的部分,也许那里有什么问题? - frnhrorigin/pr/123
的,因为PR中不应该有这样的参考(也许你有一个名为这个的远程分支?)。请尝试使用refs/remote/origin/pr/123
。当你执行获取(fetch)操作时,你应该看到被获取的内容。 - yelsayed