kyxap
kyxap

Reputation: 574

How to create second pull request and ignore all previous commits

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?

Upvotes: 1

Views: 310

Answers (1)

nj2237
nj2237

Reputation: 1278

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.

Upvotes: 1

Related Questions