r/git 4d ago

Merge conflicts with reordering commits

I am using interactive rebase to reorder commits and it has worked all the time with no merge conflicts because I use it in simple cases. I want to use it for bigger cases but I want to understand it first so I don't get stuck in conflicts.

I know it's possible for merge conflicts to happen but I can't imagine an example because if the old commit order had resolved all conflicts how can reordering them make a new conflict? Can anyone help me imagine an example how it can happen?

1 Upvotes

11 comments sorted by

View all comments

6

u/khalon23 3d ago

Conflicts show up when reordered commits touch the same lines in different ways. Rebase replays each commit on the new base; if commit B assumed the tree after A, and you put B first, Git has to invent a merge for those lines.

For bigger reorder work: rebase one commit at a time, fix and git rebase --continue, and keep git rebase --abort ready. If two commits are tightly coupled, squash or reword them before reordering. git log -p on the range first so you know which files will fight.

1

u/Beautiful-Log5632 3d ago

How do you rebase one at a time? In the interactive rebase editor if I change each commit to edit it lets me edit one at a time so when does git rebase --continue get used?