DraganS
DraganS

Reputation: 2699

Remove cherry-picked commits

Often I have to wait for the code review of PRs containing the code that I need in the new branch. I was wondering would it be possible to:

Thanks a lot.

Dragan

Upvotes: 2

Views: 4459

Answers (1)

AnoE
AnoE

Reputation: 8345

Yes, that would be perfectly possible. That said...

You can join the first two steps by just branching off of your waiting branch branch1 instead of master, then there is no need for cherry picking.

You can skip the interactive rebase as well - the common git rebase master will automatically detect that the changes from the original PR branch are already there and it will simply work as expected with minimal fuss. You can tell it to skip the commits from branch1 with the --onto option.

In summary:

git checkout branch1
git checkout -b branch2
... git commit, etc. ...
... wait for acceptance of PR of branch1, pull new master  ...
git checkout branch2
git rebase --onto master branch1 branch2

The interpretation of --onto is quite literal "cherry pick all commits between branch1 and branch2 onto master". Those commits being exactly those that you added while waiting for the PR.

Upvotes: 2

Related Questions