Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rebase "fixup" commit into prior merge commit

I have performed the following merge:

A---B---C---E (HEAD, merge of C and D)
           /
      D---|

But I noticed some issues in E, and fixed them in F:

A---B---C---E---F (HEAD)
           /
      D---|

I want to modify commit E so that it contains the "fixup" changes made in F.

When I try git rebase -p -i HEAD~2, it tries to create a regular (not merge) commit, and even tries to make me re-resolve the conflicts I already resolved when performing the merge for E.

How do I fixup commit E so it contains the changes made in F?

like image 591
Craig Otis Avatar asked Sep 07 '26 22:09

Craig Otis


1 Answers

git reset --soft E
git commit --amend  # (add --no-edit to keep the same commit message)

should be enough. It'll recreate a merge commit (with a different hash than E, let's call it E') while inserting whatever changes you made between E and F.

Note: If the changes you're squashing into the merge commit are really part of the merge, like fixing a faulty conflict resolution, all good. However, if not, this will create what is sometimes called an evil merge. Because it not only merges commits C and D, but also introduces "unrelated" changes. It doesn't "break" anything per se, but is generally frowned upon because it can confuse someone inspecting history in the future.

like image 175
Romain Valeri Avatar answered Sep 11 '26 09:09

Romain Valeri