Fre*_*all 108 git github pull-request
我想从GitHub克隆一个存储库.问题是我不想要主分支; 我希望这个未经批准的拉取请求中的版本.
我可以克隆拉取请求版本而不是主存储库吗?
Chr*_*ial 93
最简单的方法是这样的:
git fetch origin pull/2/head
git checkout -b pullrequest FETCH_HEAD
Run Code Online (Sandbox Code Playgroud)
您现在将处于处于拉取请求状态的新分支上.
ina*_*inc 76
您可以使用命令中的-b
选项克隆所需的分支git clone
.
在您的情况下,您要克隆的分支是拉取请求的源分支(feature/mongoose-support):
git clone https://github.com/berstend/frappe.git -b feature/mongoose-support /my_clone
Run Code Online (Sandbox Code Playgroud)
wie*_*iks 37
git fetch origin refs/pull/PR_NUMBER/head:NEW_LOCAL_BRANCH
Run Code Online (Sandbox Code Playgroud)
例如:
$ git fetch origin pull/611/head:pull_611
$ git checkout pull_611
Run Code Online (Sandbox Code Playgroud)
在GitHub上进行更改,提交,推送和打开新的PR
Ian*_*sco 17
你可以按照这个要点中的指示直接检查遥控器,而不必弄清楚他们的存储库和分支.
用法示例
对于我的一个项目(github3.py)我在我的项目中有以下内容 github3.py/.git/config
[remote "github"]
fetch = +refs/heads/*:refs/remotes/github/*
fetch = +refs/pull/*/head:refs/remotes/github/pr/*
url = git@github.com:sigmavirus24/github3.py
Run Code Online (Sandbox Code Playgroud)
第一行是每个远程的标准行,异常github
由远程名称替换.这意味着远程头(或该服务器上的分支头)被"映射"到前缀为的本地遥控器github/
.所以,如果我git fetch github
在GitHub上做了一个分支,但我的机器上已经没有在本地注意到它,它会下载分支,我可以这样切换到它:git checkout -t github/branch_name
.
第二行做同样的事情,但它是为拉请求而不是标准的git分支.这就是你看到的原因refs/pull/*/head
.它在GitHub上获取每个pull请求的头部并将其映射到github/pr/#
.那么如果有人发送拉取请求并且编号为62(例如),那么你会这样做:
git fetch github
git checkout -t github/pr/62
Run Code Online (Sandbox Code Playgroud)
然后你会在一个叫做的本地分支上pr/62
(假设它还没有存在).这很好,意味着你不必跟踪其他人的遥控器或分支机构.
当用户提交拉取请求时,他们要求将某些更改从其克隆的分支合并到另一个用户的存储库.
您想要的更改可以从拉取请求的来源获得.为此,克隆用户的repository(git://github.com/berstend/frappe.git
),然后检查他从(feature/mongoose-support
)创建拉取请求的分支.
小智 5
git clone git://github.com/dweldon/frappe
cd frappe
git pull origin pull/2/head
Run Code Online (Sandbox Code Playgroud)
使用Github官方新的命令行界面:
gh repo clone org/repo
cd repo
gh pr checkout 44
Run Code Online (Sandbox Code Playgroud)
其中44
是 PR 编号,但也可以是分支机构名称。