Reputation: 29
I'm trying to merge these two file contents into a new file. I already have the left and rights contents as JSON objects with line numbers and line content.
For instance, I want to select the left part and leave the right part in a new file after the merge. Since the line numbers are different. How are we going to add the left content from the 214th line?
All I want is a final JSON object capturing merge decisions with line numbers. Once I get the merge JSON. I'll use any programming language to create a new file and these changes.
NOTE: When Merging, I'm taking the right file as the main reference. I'll take a copy of the right file and add left contents as and when selected.
Upvotes: -1
Views: 764
Reputation: 488183
As Aleksey Tsalolikhin commented, what you're showing is XML, not JSON (as encoded into text). That's not such a big deal: both just provide means of encoding tree-structured data.
Git does not understand any of this. Git's merge code treats files as lines (of text). That's OK, since you plan to do the merge yourself (with code or manually or whatever).
Note that diffing or merging tree-structured data, regardless of its encoding, is inherently complex. It should not use line numbers. It probably should see if subtrees match, and if so, consider them moved, even if they have changed depth.
If you've done the merge yourself, and the result should be encoded in text, encode it in text and insert it where it goes and give Git the result as a text file. All git merge
needs is the final text file. The merge's inputs were three text files—one from the merge base commit, the second from the current commit, and the third from the other commit being merged—and what Git needs is a new text file.
So take your merge result, encode it as text, and you're basically done: write it to the appropriate file (or appropriate portion of the appropriate file) and tell Git this is the correct result of the merge. In other words, write out the result and run git add path/to/file
.
NOTE: When Merging, I'm taking the right file as the main reference. I'll take a copy of the right file and add left contents as and when selected.
There are three inputs to a merge. There isn't "left and right": there are merge base, ours, and theirs. The delta from base to ours represents what we changed. The delta from base to theirs represents what they changed. Your job is to combine these changes.
Upvotes: 1