Diff notes

From Helpful
(Redirected from Diff)
Jump to: navigation, search
These are primarily notes
It won't be complete in any sense.
It exists to contain fragments of useful information.
This article/section is a stub — probably a pile of half-sorted notes, is not well-checked so may have incorrect bits. (Feel free to ignore, fix, or tell me)

(See also comm)


diff is an utiliy to show the (minimal line-based) difference between two text files. In informal use it is useful to see where minor changes between files are.


Many prefer 'unified diff format' (-u parameter) over the default output format.


Its output can also be used by patch, to change another copy of the original file. This is used between programmers to distribute minor changes in code. In this context, it is quite helpful that diff lists its context, so more than one (non-conflicting) patch may be applied to the same file.


related utilities

  • git diff
Yes, will work without any git metadata.
Will color its output (if git is configured to).
  • sdiff
allows interactive merging
  • colordiff
wrapper around diff that colors the output.
  • vimdiff
n-way?(verify)
  • emacs's ediff-buffers



3-version comparison

For example to show two different changes to an original version, which can be useful for conflict resolution in versioning systems.

binary diff

Often to do binary patches (e.g. to save on data transfer), but also sometimes to see before/after versions of a file that got changed, e.g. in a hex-editor sort of viewer.


GUIs

  • Kompare (for KDE) [2]
  • Beyond Compare [4]


3-way:

Difference in directory structure

...as in, check only the presence of files.


The shortest trick is probably:

rsync -navi dir1/ dir2/

Note:

  • make sure -n is in there, or it will alter dir2 to match dir1
  • the slashes matter (on the first, technically)
  • This will use rsync's selection logic - i.e. is-same-timestamp-and-size.
You may sometimes want --size-only, to look only at size and make mtime irrelevant.
  • -i helps show how it's different


With content checks

The simplest graphical way is to use meld.


You could use diff itself - recursive, and ask it to just mention that files differ in contents:

diff -q -r dir1 dir2


Most other methods require more shell-fu, e.g.:

# diff -u 0 <( tree dir1 ) <( tree dir2 )

Or the three commands and temporary files:

tree dir1 > dir1tree
tree dir2 > dir2tree
diff dir1tree dir2tree