1

What I have:

Two branches branch1 and branch2 for different features, in branch1 I pushed 5 commits and created pull-request and waiting for code review. Then I done with new feature in branch2 and pushed 3 new commits in second one.

The Problem:

When I'm going to create new pull request from branch2 I see that all 8 commits will be added to this request. And for some reasons I can asked to pull only those 3 from branch2.

What I'm doing wrong?

1
  • 1
    Seems the branches moved on like this: branch1 was created from a base commit, 5 new commits were made, branch2 was created from the tip of branch1, 3 more new commits were made. If so, branch2 should have been created from the base commit too. You could rebase the 3 new commits onto the base commit, or create branch3 from the base now and then cherry-pick the 3 commits. At last create a new pull request from branch3. Commented Aug 1, 2017 at 2:16

1 Answer 1

1

An option you can try is:

(I) Once you have done 5 commits to branch1, push it to remote for code review.

(II) Checkout to branch2, if you enter git log you should see the previous 5 commits to branch1. Do a git reset --hard HEAD~5, which will turn your local repo 5 commits back. You need not worry about permanently losing those 5 commits, since they are available on the remote repo's branch1 - you can pull it whenever necessary.

(III) Make the changes on your branch2, create a new pull request for your branch2 and push those 3 commits to remote branch2 for code review. Now, the previous 5 commits will not be included in your new pull request.

Note: This option can be used when the two branches are working on separate features and do not depend on each other's updates to work. I hope this answers your question. Let me know if you have any issue.

Also, when you want the branches to be separate, right when you are creating the new branch, do a git checkout master and then git checkout -b branch2 so thatbranch2 is created from master's history, and not branch1 or your working branch. Then the branch commits will not overlap with each other, and will follow from master. So in your case, you will then have 5 commits following branch1 and 3 commits following branch2 respectively.

Sign up to request clarification or add additional context in comments.

2 Comments

hey, your comment was useful, so I have deleted branch2 (stash all before it) and before create new one used git checkout and it helped!
@kyxap glad it helped :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.