【问题标题】:How to clone/download code from a pull request如何从拉取请求中克隆/下载代码
【发布时间】:2017-07-04 23:28:15
【问题描述】:

我在 github 上找到了一个源代码。它有一些拉取请求,指示正在更改的代码。我想将其中一个下载/克隆到我的电脑上。它的 pull request id 是 3983,地址为https://github.com/BVLC/caffe/pull/3983 谢谢大家

【问题讨论】:

标签: git github


【解决方案1】:

因为有人有多个拉取请求,每个拉取请求都有自己的 ID。如何下载与拉取请求 ID 对应的正确版本

最好克隆原始repo,并导入PR branch based on its ID

git clone https://github.com/BVLC/caffe
cd caffe
git remote add christianpayer https://github.com/christianpayer/caffe.git

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

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

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

【讨论】:

  • 我尝试了您的第三个命令,但出现错误“致命:找不到远程参考拉/3983/head 命令流意外结束”。
  • 是的,这是意料之中的,因为 PR 编号仅存在于 origin repo 上:用 origin 替换 Christian payer
【解决方案2】:

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

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

现在将fetch = +refs/pull/*/head:refs/remotes/origin/pr/* 添加到config

[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文件夹吗?
  • 在那之前你必须cd所以我加了cd caffe
  • 谢谢。我也有一个问题。你怎么知道pull request 3983对应的https://github.com/christianpayer/caffe.git
  • christianpayer 想要将 32 个提交合并到 BVLC:master from christianpayer:nd-cudnn 他从主仓库分叉并从他的分叉仓库提交 PR
  • 不需要分叉存储库,人们也可以在同一个存储库中创建自己的分支。所以最好在git checkout nd-cudnn 之后查看git log --oneline 并找到您感兴趣的提交哈希。你可以在 PR 中看到他正在合并的所有提交。
猜你喜欢
  • 2013-02-03
  • 2014-04-01
  • 2016-10-01
  • 2013-02-01
  • 2018-02-25
  • 1970-01-01
  • 2021-10-31
  • 1970-01-01
  • 2013-09-22
相关资源
最近更新 更多