Skip to content

Colored Word Differences in Git

Being able to view diffs is an essential part of the workflow in keeping your LaTeX documents under version control. (You are using a version control system, right?) One limitation of diff software is that they tend to display line differences. Since paragraphs in LaTeX tend to be long lines, multiple differences within a paragraph are not marked. If you are using Git for version control, here is a quick tip. git diff comes with the option --color-words. This option highlights word differences. git diff defaults to the less pager. While git diff --color-words highlights word differences, less does not, by default, wrap long lines. However, you can invoke the -S option within less to wrap long lines. So, for a quick LaTeX-friendly diff within git try:

$ git diff --color-words

followed by -S in the subsequent less pager.

Post a Comment

You must be logged in to post a comment.
FireStats icon Powered by FireStats