We maintain a branch structure with a merge workflow. As a result our master branch commit hierarchy looks like this.
However, since we use Gitlab community edition which doesn't squash and rebase merges, sometimes developers forget to do one or the other and merge commits which look like this.
The usual way I follow to recover from this is to reset master to the last good commit before these merges and then replay every merge (after rebasing and squashing correctly) to merge them.
A better way may be to use the git rebase --onto
command to replay the good merges after the bad merges have been fixed. However, I have been unable to figure out the correct way to do this. What I do is:
I tried using git rebase -ip --onto <last_good_commit>
to replay my good merges in step 5 but that seems to exchange the order of parents for the commit. Anyone have a good way of improving my workflow so that I don't have to replay every single merge manually?
The answer by @VonC was almost correct. I had to modify the rebase command as git rebase -ipm --onto <last_good_commit> <first> <yourBranchToReplay>
and it rebased all remaining merges correctly on the fixed merges.