Skip to content

This document is a WORK IN PROGRESS.
This is just a quick personal cheat sheet: treat its contents with caution!


difftastic

difftastic is a structural diff tool that compares files based on their syntax.

Reference(s)

Table of contents


Install

Not available with apk.

Not available with apt.

Not available with dnf.

# emerge -a dev-util/difftastic
# nix-env -iA nixos.difftastic
# nix-env -iA nixpkgs.difftastic
# pacman -S difftastic

Not available with yum.

Not available with xbps.

Not available with zypper.


Config

Git external diff

  • Git supports external diff tools. You can use GIT_EXTERNAL_DIFF for a one-off git command, e.g.:

    $ GIT_EXTERNAL_DIFF=difft git diff
    

  • If you want to use difftastic by default, use git config:

    $ git config diff.external difft # Set git configuration for the current repository
    $ git config --global diff.external difft # Set git configuration for all repositories
    

    After running git config, git diff will use difft automatically. Other git commands require --ext-diff to use external diff, e.g. git log and git show:

    $ git diff
    $ git log -p --ext-diff
    $ git show e96a7241760319 --ext-diff
    

  • See also git diff.

git-difftool

  • git difftool is a git command for viewing the current changes with a different diff tool. It's useful if you want to use difftastic occasionally.

  • Add the following to your .gitconfig to use difftastic as your difftool:

    $ vi $HOME/.gitconfig # or $XDG_CONFIG_HOME/git/config or wherever
        > ...
      + >
      + > [diff]
      + >     tool = difftastic
      + >
      + > [difftool]
      + >     prompt = false
      + >
      + > [difftool "difftastic"]
      + >     cmd = difft "$LOCAL" "$REMOTE"
      + >
      + > [pager]
      + >     # Use a pager for large output, just like other git commands
      + >     difftool = true
      + >
      + > [alias]
      + >     # `git dft` is less to type than `git difftool`
      + >     dft = difftool
    

  • You can then run $ git difftool to see current changes with difftastic.

  • See also git difftool.


Use

  • Diffing files:

    $ difft sample_files/before.js sample_files/after.js
    

  • Diffing directories:

    $ difft sample_files/dir_before/ sample_files/dir_after/
    
    Difftastic will recursively walk the two directories, diffing files with the same name.

    The --skip-unchanged option is useful when diffing directories that contain many unchanged files.

  • You can read a file from stdin by specifying - as the file path:

    $ cat sample_files/before.js | difft - sample_files/after.js
    

  • Difftastic guesses the language used based on the file extension, file name, and the contents of the first lines. You can override the language detection by passing the --language option. Difftastic will treat input files as if they had that extension, and ignore other language detection heuristics.

    $ difft --language cpp before.c after.c
    

  • Difftastic includes a range of configuration CLI options, see $ difft --help for the full list. Difftastic can also be configured with environment variables. These are also visible in --help. For example, DFT_BACKGROUND=light is equivalent to --background=light. This is useful when using tools like git, where you are not invoking the difft binary directly.


If this cheat sheet has been useful to you, then please consider leaving a star here.