bhousel / node-diff3

A node.js library for text diffing and three-way-merge
Other
91 stars 13 forks source link

[Question] 2-way merge is not giving desired results. #43

Closed JayaKrishnaNamburu closed 3 years ago

JayaKrishnaNamburu commented 3 years ago

I might be using this for a use-case which it might not be designed for. So, please close this if it's not related. So, i have two code-snipped. And trying to do a 2-way merge between them. But my second snipped is always being overwritten.

Here is the url to reproduce --> https://codesandbox.io/s/vigorous-pond-mvf9u?file=/src/index.js I have a remote and a base. And every time i try a 2-way merge on it. I am loosing some content from the base. Am i doing something wrong, or should i change to diffMerge3. But even with that, i had some similar experiences.

bhousel commented 3 years ago

I'm not sure.. 2-way merge is designed to generate a patch that changes buffer1->buffer2, or invert back buffer2->buffer1. 3-way merge is designed to highlight conflicts between original buffer and a and b changed buffers.

Also, there are a bunch of different diff algorithms out there, and the one that this project uses is pretty simple. It is designed to mimic the GNU Diffutils.

For comparison, git gives you the option of using 4 different algorithms. Some work better or worse for diffing different kinds of input.

I'd recommend to look through the code in https://github.com/bhousel/node-diff3/tree/main/test to see the use-cases, then see if you can reduce the problem to a failing test case..

JayaKrishnaNamburu commented 3 years ago

Thanks for the info bhousel, will take a look. This is what confused me a little that 2-way merge can also merge two buffers. https://github.com/bhousel/node-diff3#diffPatch

// patch contains the information needed to turn buffer1 into buffer2

Will take a looks at the rest of the use-cases, thank you 😄

JayaKrishnaNamburu commented 3 years ago

Closing this @bhousel, the diffMerge3 looks promising for the use-case. Once again Thank you 😄