Home > Blockchain >  Is reorder commits safe if we get no conflict?
Is reorder commits safe if we get no conflict?

Time:11-22

Say I'm working on a project with two tickets. And has some dirty commits.

commit4 do ticket2.2
commit3 do ticket1.2
commit2 do ticket2.1
commit1 do ticket1.1

Is it safe, if I reorder it to such like this with no conflict:

commit4 do ticket2.2
commit3 do ticket2.1
commit2 do ticket1.2
commit1 do ticket1.1

I think git judge conflict using what deletes and what adds(Sometimes not very clever however). But if we reorder commits with no conflict, is it guaranteed to be the same code with previous? And how can we prove that?

I've been quite frequently using git rebase -i to reorder commits and checked git diff later, the code was same as expexted. But is it always true?

CodePudding user response:

No, it's not guaranteed to be the same code because there is a conflict, the final code cannot be determined, or includes the conflicted patch!

However, what you're doing is rebasing the commits and may indeed be what you want to do (git rebase)

Finally, the conflict may be quite important (or trivial), and you should review it before blindly rebasing over it to ensure the result is what you want and expect

CodePudding user response:

u need to understand how git rebase -i work,

it 's simply just "recommiting" patches in different order one by one.

if there was any conflict during one of the commits , git would interrupt the rebase operation, and ask u to resolve the conflict, after that u continue for the next commit.

in conclution

If git doesn't interrupt your rebase operation, it means that there is no conflict at all. don't worry~

  • Related