One of my main gripes regarding git is that it just generates diffs per line regardless of context or document format. This can be frustrating as it often leads to diffs that cover the end of a function declaration that was not touched and leaves out the end of a function that was just added.

Git supports diff options such as patience and histogram but , even though they mitigate some problems, they are still fallible.

So does anyone know if there is any way to get git to do context- or document format-sensitive diffs?

  • Jakub Narębski@programming.dev
    link
    fedilink
    English
    arrow-up
    2
    ·
    1 year ago

    With gitattributes you can configure custom diff driver and custom merge driver for a specific file type.

    For example:

    • diff-tools include some tools that work as diff driver, but it is a bit undocumented in regards to what those diff drivers do, and for what files they should be used
    • nbdime tool for better diffing and merging of Jupyter notebooks can work as either diff driver, or as graphical diff interface (as difftool)