No, it's not guaranteed to be the same code because there is a conflict, the final code cannot be determined, or (somewhat of a stretch) 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 (otherwise you can go further and evilly clobber any merges with your side git merge -s recursive -X ours vs git merge -s ours? .. which is also likely to give quite different and very undesirable results)
If there's no conflict (or you resolved the conflict), you can compare the before and after state with git diff
git checkout branchA # commits in order A
git diff HEAD~4.. > testA.patch # save output
git checkout branchB # commits in order B
git diff HEAD~4.. > testB.patch
diff testA.patch testB.patch # ideally no differences here
Here, ~4
is the -4th commit, inclusive, so if you added a merge commit, you might have ~5
.. it may also be easier to name the commits aaaaaaa..fffffff
, but that will of course vary by-use
Finally, there's some difference between always being certain and the common case of plain text (code) files
With the former "always" / "in every case", it's likely you will find ugly edges around the addition of something like .gitattributes
or .gitignore
, which when reflowed could make all sorts of exciting changes, like changing a filter rule or no longer including it!
While with the latter (and likely more common) case of plain text files, simply diff
is sufficient (though you should still be observant of special attributes)