如何在GitHub上使用其他人的拉取请求中的代码?

时间:2019-04-13 00:07:54

标签: git github

我的问题主要取决于使用Git。我目前正在使用Elastalert的官方GitHub存储库中的代码,但他们尚未添加对本周刚刚发布的Elasticsearch版本7的支持。我看到另一个用户添加了他的代码来解决此问题和there is a pull request in GitHub here。有没有一种方法可以从拉取请求中克隆此用户的代码,而不是从Elastalert存储库中克隆官方代码?在这种情况下,官方存储库不适用于我们的Elasticsearch版本,并且我不想等待Yelp批准请求请求。我是使用Git和GitHub的新手,所以基本的解释将是很棒的。

1 个答案:

答案 0 :(得分:1)

拉取请求是一个分支。 Github以<image xlink:href="/static/media/circle.ffe52f1d.png" height="60" transform="translate(-30,-30)"></image> 的格式命名这种分支。您感兴趣的请求请求的编号为refs/pull/${number}/head,因此名称为2194。这种分支不能用作refs/pull/2194/head中选项-b的值,但可以在git clone中使用。

git fetch

然后您可以在# initialize a local repository "foo". If "foo" already exists, "git init foo" is harmless. git init foo cd foo # create a remote "origin". It is optional. If "origin" is occupied, use another name. git remote add origin https://github.com/Yelp/elastalert.git # fetch the pull request git fetch origin refs/pull/2194/head # if you didn't create the remote "origin" git fetch https://github.com/Yelp/elastalert.git refs/pull/2194/head # create a local branch "bar" from this pull request git checkout -b bar FETCH_HEAD # if you don't want to keep the history of the pull request git checkout --orphan bar FETCH_HEAD git commit 上进行新的提交。

相关问题