gpbaculio
gpbaculio

Reputation: 5968

Pull request contains my commits on other branch?

i am aware of this changing branch base trick and it's not working, from this question: GitHub pull request showing commits that are already in target branch

in my case, i am getting MY commits from other branch i work on before switching to a branch. How do i fix this?

Upvotes: 2

Views: 2907

Answers (1)

Vasil Velichkov
Vasil Velichkov

Reputation: 1324

One relatively easy solution is to create a complete new branch from the master (or the branch you want to merge into) and then cherry-pick only the commits you want to include in the PR one by one from your old branch. And then you need to force push to github using the original branch name.

git checkout -b new_attempt origin/master
git cherry-pick <commit1>
git cherry-pick <commit2>
...
git push --force origin new_attempt:mybranch

where the mybranch is the name of the branch you've used for this PR.

If the commits are too many you can try rebase with --onto option.

git rebase --onto origin/master <base_commit> mybranch
git push --force origin mybranch

where the <base_commit> is the last commit you want to exclude from the PR. Rebasing could be bit tricky so make a backup and read git-rebase docs

Upvotes: 7

Related Questions