如何从拉取请求中克隆/下载代码

6

我在Github上找到了一份源代码。它有一些拉取请求(Pull Request),表示正在更改代码。我想要下载/克隆其中一个到我的电脑。它的拉取请求编号是3983,网址为https://github.com/BVLC/caffe/pull/3983

谢谢。


https://dev59.com/AWUp5IYBdhLWcg3w665C - Mohammad Ali
2个回答

13
因为有人提交了多个拉取请求,每个拉取请求都有自己的ID。我该如何下载与拉取请求ID相对应的正确版本?
最好是克隆原始存储库,并根据其ID导入拉取请求分支
git clone https://github.com/BVLC/caffe
cd caffe
git remote add christianpayer https://github.com/christianpayer/caffe.git

然后,对于christianpayer合并到origin的一个PR:

git fetch origin pull/3983/head:pull_3983
git checkout pull_3983

你可以从该远程仓库获取其他PR,或者添加其他远程仓库以获取其他PR。

我尝试了你的第三个命令,但是出现了错误:“fatal: Couldn't find remote ref pull/3983/head Unexpected end of command stream”。 - John
是的,这是预期的,因为PR号仅存在于原始存储库上:将Christian payer替换为origin。 - VonC

1
有两种方法可以做到这一点:

1:

git clone https://github.com/christianpayer/caffe.git
cd caffe
git checkout nd-cudnn

这是从这里开始的:

https://github.com/christianpayer/caffe/tree/nd-cudnn

2:

git clone https://github.com/BVLC/caffe.git

cd caffe/.git

现在在config中添加以下行:fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

[remote "origin"]
        url = https://github.com/BVLC/caffe.git
        fetch = +refs/heads/*:refs/remotes/origin/*
        fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

现在获取所有的拉请求:
$ git fetch origin
From github.com:joyent/node
 * [new ref]         refs/pull/5190/head -> origin/pr/5190
 * [new ref]         refs/pull/5193/head -> origin/pr/5193
 * [new ref]         refs/pull/5198/head -> origin/pr/5198
 * [new ref]         refs/pull/520/head -> origin/pr/520

...

要查看特定的拉取请求:
$ git checkout pr/3983
Branch pr/3983 set up to track remote branch pr/3983 from origin.
Switched to a new branch 'pr/3983'

git checkout nd-cudnn 是什么?因为当我使用它时出现了“fatal:Not a git repository(or any of the parent directories): .git”的错误。我需要先进入caffe文件夹吗? - John
你必须在此之前执行 cd 命令,因此我添加了 cd caffe - Avinash
谢谢。我还有一个问题。您如何知道https://github.com/christianpayer/caffe.git对应于拉取请求3983? - John
christianpayer想要将32个提交合并到BVLC:master分支中,这些提交来自于christianpayer的nd-cudnn分支。他从主仓库fork了一个副本,并从他的副本仓库提交了PR。 - Avinash
所以,每个人想要发起一个拉取请求,他都必须有一个分叉版本。我们只需访问他的网站并找到它即可。对吗?因为有些人可能会有多个拉取请求,每个拉取请求都有自己的ID。我该如何下载与拉取请求ID相对应的正确版本呢? - John
1
不必分叉存储库,人们也可以在同一存储库中创建自己的分支。因此,在执行“git checkout nd-cudnn”之后,最好查看“git log --oneline”,找到您感兴趣的提交哈希值。您可以在PR中查看他正在合并的所有提交。 - Avinash

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接