git 来自拉取请求的 GitHub 克隆?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14947789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GitHub clone from pull request?
提问by Fresheyeball
I would like to clone a repository from GitHub. The problem is I don't want the main branch; I want the version in this unapproved pull request.
我想从 GitHub 克隆一个存储库。问题是我不想要主分支;我想要这个未经批准的拉取请求中的版本。
Is it possible for me to clone the pull request version instead of the main repository?
我可以克隆拉取请求版本而不是主存储库吗?
采纳答案by inancsevinc
You can clone the branch you want by using the -b
option and for pull request:
您可以通过使用-b
选项和拉取请求来克隆您想要的分支:
git clone https://github.com/user_name/repo_name.git -b feature/pull_request_name dir_name
In your case, the branch you want to clone is the source branch of the pull request (feature/mongoose-support
):
在您的情况下,您要克隆的分支是拉取请求 ( feature/mongoose-support
)的源分支:
git clone https://github.com/berstend/frappe.git -b feature/mongoose-support ./mongoose-support
回答by Chronial
The easiest way to do that is like this:
最简单的方法是这样的:
git fetch origin pull/2/head
git checkout -b pullrequest FETCH_HEAD
You will now be on a new branch that is on the state of the pull request.
您现在将位于处于拉取请求状态的新分支上。
You might want to set up an alias by running
您可能希望通过运行来设置别名
git config --global alias.pro '!f() { git fetch -fu ${2:-origin} refs/pull//head:pr/ && git checkout pr/; }; f'
Now you can checkout any PR by running git pr <pr_number>
, or git pr <pr_number> <remote>
if your github remote is not named origin
.
现在,您可以通过运行检出任何 PR git pr <pr_number>
,或者git pr <pr_number> <remote>
如果您的 github 远程未命名origin
。
回答by wierzbiks
git fetch origin refs/pull/PR_NUMBER/head:NEW_LOCAL_BRANCH
eg:
例如:
$ git fetch origin pull/611/head:pull_611
$ git checkout pull_611
Make changes, commit them, PUSH and open new PR from your fork on GitHub
进行更改、提交、推送并从 GitHub 上的 fork 打开新的 PR
回答by Ian Stapleton Cordasco
You could follow the directions in this gistto be able to check out the remote directly without having to figure out their repository and branch.
您可以按照本要点中的说明直接检查远程,而无需找出他们的存储库和分支。
Example usage
示例用法
For one of my projects (github3.py) I have the following in my github3.py/.git/config
对于我的一个项目(github3.py),我的项目中有以下内容 github3.py/.git/config
[remote "github"]
fetch = +refs/heads/*:refs/remotes/github/*
fetch = +refs/pull/*/head:refs/remotes/github/pr/*
url = [email protected]:sigmavirus24/github3.py
The first line is what is standard for every remote with the exception that github
is replaced by the remote's name. What this means is that remote heads (or the heads of branches on that server) are "mapped" to local remotes prefixed by github/
. So if I did git fetch github
and had a branch on GitHub that wasn't already noticed locally on my machine, it would download the branch and I could switch to it like so: git checkout -t github/branch_name
.
第一行是每个遥控器的标准内容,但github
被遥控器名称替换的例外。这意味着远程头(或该服务器上的分支头)被“映射”到以github/
. 因此,如果我这样做git fetch github
并且在 GitHub 上有一个在我的机器上本地尚未注意到的分支,它会下载该分支,我可以像这样切换到它:git checkout -t github/branch_name
.
The second line does the same thing, but it does it for pull requests instead of standard git branches. That's why you see refs/pull/*/head
. It fetches the head of each pull request on GitHub and maps it to github/pr/#
. So then if someone sends a pull request and it is numbered 62 (for example), you would do:
第二行做同样的事情,但它是针对拉取请求而不是标准的 git 分支。这就是为什么你看到refs/pull/*/head
. 它获取 GitHub 上每个拉取请求的头部并将其映射到github/pr/#
. 因此,如果有人发送拉取请求并且编号为 62(例如),您将执行以下操作:
git fetch github
git checkout -t github/pr/62
And then you would be on a local branch called pr/62
(assuming it didn't already exist). It's nice and means you don't have to keep track of other people's remotes or branches.
然后你会在一个名为pr/62
(假设它不存在)的本地分支上。这很好,意味着您不必跟踪其他人的遥控器或分支机构。
回答by Steven Penny
git clone git://github.com/dweldon/frappe
cd frappe
git pull origin pull/2/head
How can I fetch an unmerged pull request for a branch I don't own?
回答by adrianbanks
When a user submits a pull request, they are asking for some changes to be merged from a branch on their clone of a fork back to another user's repository.
当用户提交拉取请求时,他们要求将一些更改从他们的复刻副本上的分支合并回另一个用户的存储库。
The changes you want can be got from the source of the pull request. To do this, clone the user's repository (git://github.com/berstend/frappe.git
), and then check out the branch he created the pull request from (feature/mongoose-support
).
您想要的更改可以从拉取请求的来源获得。为此,请克隆用户的存储库 ( git://github.com/berstend/frappe.git
),然后检出他从 ( feature/mongoose-support
)创建拉取请求的分支。
回答by megawac
After installing git-extras
(cd /tmp && git clone --depth 1 https://github.com/tj/git-extras.git && cd git-extras && sudo make install)
You can simply use git pr
你可以简单地使用 git pr
$ git pr 62 [remote]
回答by Kartik
That pull request shows the commits from that person's fork so you can see that he is pushing his changes from feature/mongoose-support
branch.
该拉取请求显示来自该人的分支的提交,因此您可以看到他正在从feature/mongoose-support
分支推送他的更改。
You can clone his repository and checkout that branch
您可以克隆他的存储库并签出该分支
回答by stevec
回答by Xavier Guihot
With Github's official new command line interface:
使用 Github 的官方新命令行界面:
gh repo clone org/repo
cd repo
gh pr checkout 44
where 44
is the PR number, but can also be the branch name.
其中44
是 PR 编号,但也可以是分支名称。
See additional details and optionsand installation instructions.