Git rebase --onto
February 17, 2022 -Squashed commits can pose a problem when there is a chain of branches, e.g.:
branch-1
targetsmain
, contains commit Abranch-2
targetsbranch-1
, contains commit A and commit B
Imagine that before merge, a subsequent commit is made in branch-1
, so it is now A + C
. Upon merge, this becomes A'
on main
because we use squash commits.
Now we have a problem: main
has A'
but branch-2
has A + B
. It's a merge conflict!
The solution: git checkout branch-2
and git rebase --onto main branch-1
.
More details here.