Reputation: 1480
I forked a repo on github, then I did git checkout X
and made some changes to branch X
. After finishing up, I made a pull request from branch X
of the forked repo to branch X
of the original repo.
My changes got merged with branch X
of the original repo, then I made some more changes and made another pull request from my branch X
to original repo's branch X
. However, this still shows my previously merged commits as under,
Here, commits made till Jul 05, 2017
have already been merged to branch X
of the original repo. I only need the commits on Jul 06
to show up on this pull request. After trying for quite some time I'm unable to find a solution. Here's what I did based on this post,
git remote add upstream https://path/to/original/repo.git
git fetch upstream
git rebase X
However, now I see an even bigger list of commits staged for the pull request. I'm sure I don't fully understand how pull requests work but I'm assuming this is because my forked repo does not know that previous commits have already been merged.
I know the usual workflow should be to fork the repo, make a new branch for every change, make a pull request, delete the branch once changes have been merged. I wasn't aware of that and stumbled on this problem. How do I only include the newly (un-merged) commits in the pull request, and not all the previous ones as well?
Upvotes: 3
Views: 2772
Reputation: 4485
One way is to cherry-pick the commits from a fresh new branch from upstream:
git fetch upstream X:X_new
git checkout X_new
git cherry-pick 92495c5
git cherry-pick ...
You can then open a new pull request. If you want to keep the same pull-request, you will need to rename it to the old name, and force push to your repo:
git checkout X
git checkout -b X_backup
git branch -D X
git checkout X_new
git checkout -b X
git push origin X -f
and then if it fits your need, you can delete the other branches:
git branch -D X_backup
git branch -D X_new
Upvotes: 3