81

I have a repository that is forked from GitHub that has a few modifications made to it. However, in a certain commit, a few files were changed that I want to submit a pull-request for, leaving the other modified files out of the request.

Do pull requests merge all commits, or do I need to do something special to isolate this commit?

3

2 Answers 2

45

A pull request being made of whole commits, you need to split this commit into two separate commits one containing the change to put in the pull request, and the other holding the other changes. To do this you need git rebase -i, see for example How can I split up a Git commit buried in history? for a good explanation on how to do it.

Once you have split the commit, move the ones you want to include into a topic branch, see for example How to move certain commits to another branch in git?, but it depends if the commits that make your pull request are sequential.

Then finally you can push to Github and create the pull request from your topic branch.

4
  • 4
    For the record, git cherry-pick is an invaluable tool. Aug 11, 2015 at 20:34
  • 22
    I see this is the accepted answer; but where, exactly, are the steps to perform so one can take changes to one file in a pull request that modifies multiple files?
    – jww
    Jan 11, 2016 at 13:13
  • What happens when you are the person merging the request, and not making the request? This tool is so lame...
    – jww
    May 9, 2017 at 3:31
  • @jww Then you ask the pull request author to rebase on top of master and only include the specific changes. :) May 15, 2017 at 8:32
18

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).

1
  • 7
    Given I already made the changes in one branch, how would you achieve this? Jan 15, 2020 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.