6

I found a source code in github. It has some pull request which indicates the changing code. I would like to download/clone one of them to my PC. Its pull request id is 3983 at the address https://github.com/BVLC/caffe/pull/3983 Thank all

John
  • 2,838
  • 7
  • 36
  • 65

2 Answers2

13

Because, someone has more one pull request, each pull request has own ID. How can I download correct version which corresponds to pull request ID

It is better to clone the original repo, and import the 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

Then, for one of christianpayer's merged PR into origin:

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

You can fetch other PRs from that remote repo, or add other remote repos for fetching other PRs.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I tried your third command and I got the error "fatal: Couldn't find remote ref pull/3983/head Unexpected end of command stream". – John Feb 16 '17 at 06:20
  • Yes, that is expected since the PR number exists only on origin repo: replace Christian payer by origin – VonC Feb 16 '17 at 06:37
1

There are two ways to do this:

1:

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

It is from here:

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

2:

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

cd caffe/.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to config

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

Now fetch all the pull requests:

$ 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

...

To check out a particular pull request:

$ git checkout pr/3983
Branch pr/3983 set up to track remote branch pr/3983 from origin.
Switched to a new branch 'pr/3983'
Avinash
  • 2,093
  • 4
  • 28
  • 41
  • What is git checkout nd-cudnn? Because I got the error when using it `fatal: Not a git repository (or any of the parent directories): .git` Do I need go to caffe folder first? – John Feb 16 '17 at 03:11
  • You had to `cd` before that so I added `cd caffe` – Avinash Feb 16 '17 at 03:13
  • Thanks. I also have a question. How do you know the `https://github.com/christianpayer/caffe.git` corresponding to pull request 3983? – John Feb 16 '17 at 03:13
  • christianpayer wants to merge 32 commits into BVLC:master from christianpayer:nd-cudnn he forked from main repo and filed PR from his forked repo – Avinash Feb 16 '17 at 03:19
  • So, everyone want to make a pull request, he will have a forked version. We just go to his website and find it. Is it right? Because, someone has more one pull request, each pull request has own ID. How can I download correct version which corresponds to pull request ID – John Feb 16 '17 at 04:49
  • 1
    forking repository is not necessary, people can create their own branch also in the same repo. So best would be after `git checkout nd-cudnn` you look into `git log --oneline` and find the commit hash in which you are interested. You can see in PR what all commits he is merging. – Avinash Feb 16 '17 at 05:38