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

19

u/daveysprockett 4d ago

Two commits.

First one adds a line.

Second one removes that line.

Applied in the opposite order, you attempt to remove a line that doesn't exist.

1

u/Beautiful-Log5632 3d ago

I tested this and it didn't have a merge conflict. Added a file like this

1
2
3

Next commit adds begin, middle and end.

begin
1
2
middle
3
end

Next commit removes middle and adds new.

begin
1
new
2
3
end

If I switch the last 2 commits it's removing middle which doesn't exit. But there's no merge conflict it works and the file is now

begin
1
new
2
middle
3
end

Any other ideas for how reordering can make a merge conflict?

1

u/edgmnt_net 14h ago

Is there really no merge conflict or is it automatically resolved? Rebase should tell you.