如何在GitHub中执行一个pull请求,只有分叉库的master分支中有最新的提交 [英] How to do a pull request in GitHub with only the latest commit in the master branch of my forked repository

查看:378
本文介绍了如何在GitHub中执行一个pull请求,只有分叉库的master分支中有最新的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在github上分配了一个仓库。我做了一些更改并做了一个pull请求。

现在我做了一些其他更改并希望执行新的请求,但在执行请求之前的预览屏幕上它显示了旧的提交(那些已经被接受的提交)。

如何仅选择分叉存储库的主分支中的最新提交,以便我可以做一个只有提交的请求?

解决方案

这个答案来自一位同事,解决了我的问题:

  git checkout -b NEW_BRANCH_NAME LAST_COMMIT_NAME_BEFORE_THE_ONE_WANTED 
git cherry-pick COMMIT_NAME_WANTED
git push origin NEW_BRANCH_NAME

然后在GitHub上,您可以为您创建的新分支做一个pull请求。



更新



当我第一次开始使用git时,我问及回答了这个问题。现在我对它有了更多的了解,我想扩展这个答案。



使用叉子时,您可能希望保持原始回购。因此,这些将是我今天要遵循的步骤:

  git remote add upstream GIT_URL_OF_THE_ORIGINAL_REPO 

现在您有一个名为上游的引用,指向该回购。默认情况下,你还应该有另一个称为 origin 的指针,在这种情况下,它指向你的fork。 上游 origin 就是人们通常如何命名这些引用,但是您可以使用任何您想要的名称。



现在您需要获取最新的更改:

  git fetch upstream 

然后如果你想用 upstream 你会这样做:

  git checkout master //检出你的主分支
git merge upstream / master //将更改从上游主分支合并到您签出的分支中(master)
git push origin master //如果您想将更新后的主体推送到远程分支

>:


$ b $ pre $ g $ f $ g $ git fetch upstream //从原始仓库获取最新更改
git checkout -b my_new_feature upstream /大师//创建一个新的分支,从ma开始在原始回购中的
git cherry-pick WHATEVER_COMMIT_I_WANT //选择我想要的提交并将其添加到此新分支
git push origin my_new_feature //将新分支推送到我的分支

然后我会为 my_new_feature 分支申请一个新的PR。 / p>

只需修改/添加一个文件,然后执行,就可以替换 git cherry-pick WHATEVER_COMMIT_I_WANT > git add FILENAME git commit -m解决一些问题


I forked a repository on github. I made some changes and did a pull request.

Now I made some other changes and want to do a new pull request, but on the preview screen before doing the pull request it shows the old commits too (the ones that were already accepted).

How do I select only the latest commit in the master branch of my forked repository so that I can do a pull request with only that commit?

解决方案

This answer from a coworker fixed my problem:

git checkout -b NEW_BRANCH_NAME LAST_COMMIT_NAME_BEFORE_THE_ONE_WANTED
git cherry-pick COMMIT_NAME_WANTED
git push origin NEW_BRANCH_NAME

Then on GitHub you can do a pull request for the new branch you created.

UPDATE

I asked and answered this question when I first started working with git. Now that I know more about it, I'd like to expand this answer.

When working with a fork you probably want to keep it updated with respect to the original repo. So these would be the steps I would follow today:

git remote add upstream GIT_URL_OF_THE_ORIGINAL_REPO

Now you have a reference called upstream which points to that repo. By default you should also have another one called origin which would point to your fork in this case. upstream and origin is just how people usually name these references, but you can use whatever name you want.

Now you need to get the latest changes:

git fetch upstream

Then if you want to update your fork with changes from upstream you'd do this:

git checkout master //checkout your master branch
git merge upstream/master //merge changes from the master branch in upstream into the branch you checked out (master)
git push origin master //if you want to push your updated master to your remote fork

Now, to answer the original question, what I would do today if I wanted to submit a new PR, would be:

git fetch upstream //get the latest changes from the original repo
git checkout -b my_new_feature upstream/master //create a new branch, starting from the master in the original repo
git cherry-pick WHATEVER_COMMIT_I_WANT //select the commit I want and add it to this new branch
git push origin my_new_feature //push a new branch to my fork

Then I would request a new PR for the my_new_feature branch.

You can replace git cherry-pick WHATEVER_COMMIT_I_WANT with just modifying/adding a file and then doing git add FILENAME, git commit -m "Fixing some stuff".

这篇关于如何在GitHub中执行一个pull请求,只有分叉库的master分支中有最新的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆