Remove git merges from the middle

We maintain a branch structure with a merge workflow. As a result, our commit branch hierarchy is as follows.

Expected Hierarchy

However, since we use the Gitlab community edition, which does not squash and rebase merge, sometimes developers forget to do one or the other and compile merges that look like this.

Bad mergers

The usual way that I follow to restore this is to reset master until the last good commit before these merges, and then replay each merge (after the correct reboot and distribution) to combine them.

A better way would be to use the command git rebase --ontoto replay good merges after eliminating the bad merges. However, I could not find the right way to do this. What am I doing:

  • Reset .
  • Rebase bad commit ( -rebased) .
  • - .
  • .
  • , , 2-3.

git rebase -ip --onto <last_good_commit>, 5, , , . - , ?

+4
2

@VonC . rebase git rebase -ipm --onto <last_good_commit> <first> <yourBranchToReplay>, .

0

git rebase -ip --onto <last_good_commit> .

:

git rebase -imp --onto <last_good_commit> <first> <yourBranchToReplay>

"yourBranchToReplay", .
<first>, , <last_good_commit>

OP, -m (--merge).
-p --preserve-merge Git 1.8.5 2013

0

Source: https://habr.com/ru/post/1695607/


All Articles