When I do version control on text (or latex) files I often run into the problem that the merge/diff tools are all line based while text files are not. This leads to insufficient granularity: every paragraph with the slightest change marked as different or, with hard wrap, every line after reflow of paragraph marked as different.

Are there any tools specifically for comparing/merging text files which avoid this problem? Ideally, this would let me revert at a sentence or sub-sentence granularity level and intelligently group changes.

I'm aware that latex-diff exists and that may be great for visualizing changes. I want a tool that works on the source.

EDIT: Since all the merge programs seem to be line based (wdiff is nice but without line numbers and merge functionality not appropriate) a stopgap solution would be a merge program that made it easy to select part of a line to revert (or even made it easy to just jump in and edit the line by hand during the merge). I'm currently using Filemerge on os x which doesn't seem to allow this (ideally it would be GUI as I don't use it enough to warrant memorizing keystrokes).

Still I would prefer something specifically designed to allow this. I wouldn't think it would be that hard.

  • 1
    A different diff tool may be helpful in this case - found a related question, the answer there recommends using wdiff -al <file1> <file2> since wdiff does a word-by-word comparison instead of lines. A few other nice suggestions too - stackoverflow.com/questions/2604915/… – ivanivan Dec 26 '17 at 2:31
  • Maybe try meld. – muru Dec 26 '17 at 6:38
  • @muru That works line-based, too, as it is a devloper tool. – Murphy Dec 27 '17 at 18:33

All the graphical diff tools I know of (Meld, KDiff3, Kompare, vimdiff) are working line-based, as they are developer tools. However I see a possibility to tweak them so you may be able to use them for your purpose. It depends on whether you can do without the linebreaks (newlines, ASCII 10) in your source files within paragraphs, or are able to remove them temporarily for the comparison and reformat the source later.

In this case you could compare the texts by merging the paragraphs into one single line. Meld for instance has a setting for linewrapping for better readability (no hard linebreaks inserted), and also the possibility to define text filters which enable you to ignore irrelevant content, e. g. formatting tags/commands. I made a little HTML example to show you what I'm thinking of:

Meld diffing lorem text with HTML tags

The (crude, overgeneralizing and very basic) Python regex for HTML tags is <.*?>.

  • Yah, I already have all paragraphs as single lines. What I want is to be able to merge PARTS of a line, e.g., select one sentence to revert and leave the next one unchanged. – Peter Gerdes Dec 31 '17 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.