How do I merge a pull request into a feature branch of my github project?

瘦欲@ 提交于 2019-12-07 08:58:53

问题


Someone has submitted a pull request to my GitHub project from a fork. Rather than merging directly into master, I would prefer to merge the changes into a feature branch so that I can make some minor edits before merging the final product into master. If at all possible, I'd like GitHub to indicate to the submitter that the request was accepted (I want to encourage and recognize contributions!). Is this possible? How do I go about it?


回答1:


It would be nice if you could change the merge target of a pull request. It would also be nice if you could collaborate on a pull request before accepting it to fix minor problems. AFIAK Github doesn't allow either of those things. You have these choices...

  1. Do the merge manually and thank the author in a comment on the PR explaining why it wasn't merged straight into master.
  2. Ask the author to resubmit the pull request on the feature branch.
  3. Ask the author to make the fixes.

I would #1 because it requires less work on the part of the author. They're a volunteer, they've done the work, their job should be done. The best thank you would be to accept their work. Asking them to do administrative work just so you can better say "thanks" is a waste of their volunteer time. Asking them to fix minor edits that would probably take longer to explain than just do them. I don't think anyone will be put out by not having their PR formally accepted. Their commits will still show up in your project crediting them.

There are occasions to do #3. Usually when you feel the minor fixes will help the person make better future contributions. My usual stance is for the first submission I fix minor problems myself and note the fixes in a comment on the PR ("Hey, I fixed up some minor stuff in ABC123.") If they continue to make the same mistakes, then it might be worth commenting on their commits and having them do the fixes. You'll also want to make sure you have a contribution guide and it's up to date.




回答2:


This is possible! First create a feature branch:

$ git checkout -b my-feature

Then pull and merge the pull request's changes to your new feature branch:

$ git pull https://github.com/user/fork.git

Make your minor adjustments in a new commit:

$ # make changes
$ git commit -am "my minor changes"

Then merge your feature branch into master and push to github.

$ git checkout master
$ git merge my-feature
$ git push origin master

This will be reflected on the pull request on github.com, and you can leave a comment thanking the submitter if you like.




回答3:


Firstly you should create a copy of the branch that the pull-request is targeting. After that you can change the branch by editing the Pull-Request that was opened (even if it was not opened by you) by clicking the edit button (See the images below). Once you have done that you should double-check if the target branch was changed.

If it changed successfully then you can merge the PR into the new branch.

Edit button location

Branch selection when clicking the edit button

Changed target branch




回答4:


I recently had to accept a contributor's PR and I followed the below process:

git fetch <fork-url> <PR-branch name>

The above command should give you a FETCH_HEAD (which is a short-lived reference to keep track of what has just been fetched from the remote repository)

Now create a branch out of this FETCH_HEAD as a 'start point'

git checkout -b my-feature-branch FETCH_HEAD

Now since you got the local branch, you can do the usual stuff like re-base, merge etc.

Once you merged this branch with master and pushed it, I would put in the commit hash the on contributor's PR and thank him :-)



来源:https://stackoverflow.com/questions/28254463/how-do-i-merge-a-pull-request-into-a-feature-branch-of-my-github-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!