Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub: Accept Pull Request, But Only Some Commits

Tags:

git

github

Say you've got a user who made a few commits and rolled them into one pull request. You want to accept one of the commits, but reject the others. Is this possible with GitHub?

like image 454
Calvin Froedge Avatar asked Aug 26 '11 23:08

Calvin Froedge


People also ask

How do I pull only certain commits?

Go to either the git log or the GitHub UI and grab the unique commit hashes for each of the commits that you want. "Cherry pick" the commits you want into this branch. Run this command: git cherry-pick super-long-hash-here . That will pull just this commit into your current branch.

How do I only add certain files to a pull request?

Pull requests merge branches. So if you want to isolate some things for a pull request, best is to put those changes in a separate branch. Advantage is that you can change the pull request by pushing new changes to that branch (even push -f if you need to change already pushed commits).

How do you raise PR for a specific commit?

There is no option to create PR with selected commits. If you want to create PR with selected commits you need to create temp branch and do git cherry-pickup commits and raise the PR with temp branch.


2 Answers

Next to the "Merge pull request" button, there should be a "Use the command line" link to instructions on how to do it manually. You should follow these instructions (create new local branch and pull in their changes), but then instead of merging that whole branch back into master, you just cherry-pick the commits you want.

e.g. to review a pull request from user: jashkenas, in their branch: new-feature

git checkout -b jashkenas-new-feature master git pull https://github.com/jashkenas/YOUR_REPO_NAME.git new-feature 

And then do your testing, and then when you're ready:

git checkout master git cherry-pick COMMIT_HASH_1 git cherry-pick COMMIT_HASH_2 # etc git push origin master 
like image 96
jackocnr Avatar answered Sep 22 '22 08:09

jackocnr


Yes, you can manually accept certain commits using git-cherry-pick and then close the pull request.

  • https://help.github.com/articles/using-pull-requests
like image 20
Ciaran Avatar answered Sep 18 '22 08:09

Ciaran