Ответ 1
Rebase обычно не сохраняет комманды слияния без --preserve-merges
Хорошо, поэтому я не совсем уверен, что произойдет, если вы попытаетесь раздавить слияние с использованием интерактивной rebase с помощью --preserve-merges
... но это то, как я удалю фиксацию слияния в вашем случае и сделаю ваш история линейная:
-
Восстановите все до того, как слияние будет выполнено поверх удаленной ветки.
-
Черри-выбор или перебазирование всего после того, как слияние будет выполнено поверх ранее перезаписанных коммитов.
Если у вас есть только 1 фиксация после фиксации слияния
Итак, с точки зрения команд, это выглядело бы примерно так:
# Reset to commit before merge commit
git reset --hard <merge>^
# Rebase onto the remote branch
git rebase <remote>/<branch>
# Cherry-pick the last commit
git cherry-pick 1abcd
Если у вас более 1 фиксации после фиксации слияния
# Leave a temporary branch at your current commit
git branch temp
# Reset to commit before merge commit
git reset --hard <merge>^
# Rebase onto the remote branch
git rebase <remote>/<branch>
# Cherry-pick the last commits using a commit range.
# The start of the range is exclusive (not included)
git cherry-pick <merge>..temp
# Alternatively to the cherry-pick above, you can instead rebase everything
# from the merge commit to the tip of the temp branch onto the other
# newly rebased commits.
#
# You can also use --preserve-merges to preserve merge commits following
# the first merge commit that you want to get rid of...but if there were
# any conflicts in those merge commits, you'll need to re-resolve them again.
git rebase --preserve-merges --onto <currentBranch> <merge> temp
# These next steps are only necessary if you did the rebase above,
# instead of using the cherry-pick range.
#
# Fast-forward your previous branch and delete temp
git checkout <previousBranch>
git merge temp
git branch -d temp