Reputation: 803
Assume I have the following scenario
1->2->3 (continued-work)
/
X->Y (feature-branch)
/
A->B->C->D (master)
I am jumping back and forth between continued-work and feature-branch as I alternate between addressing code review feedback and building upon that work. After the work on feature-branch is signed off on, I want to squash those down into one commit ("Z"), rebase off of master and merge, so master looks like
A->B->C->D->Z (master)
However doing so leaves continued-work in a bad place since I've messed with its ancestors and doing any sort of merge or rebase with it causes all sorts of merge conflicts. Is there a "right" way get from my starting scenario to
1->2->3 (continued-work)
/
A->B->C->D->Z (master)
Upvotes: 4
Views: 2876
Reputation: 10931
git rebase --onto is your answer.
When you squash your commits down, do it in a different branch.
git checkout feature-branch
git checkout -b squashed-feat
git rebase <sha A> -i
then rebase that on top of master
git rebase master
That will get you to you're 2nd last step as defined above:
A->B->C->D->Z (master)
Then I would rebase the last commits with the following:
git rebase --onto master feature-branch continued-work
we do the first squashed rebase in a different branch to still have the nice branch reference to the feature-branch
. Otherwise, we could still do it but just reference the sha-id of where the feature-branch was instead of the branch name feature-branch
Upvotes: 4