diff shows the differences between two files. Its output format, the "unified diff", is the lingua franca of source-code changes, understood by patch, email-based patch workflows, and of course Git.
diff file1 file2 # default "normal" output
diff -u file1 file2 # unified format (most common)
diff -r dir1 dir2 # recursive: compare directory trees
diff -q dir1 dir2 # report only which files differ
diff -y file1 file2 # side by side
diff -w file1 file2 # ignore whitespace differences
Unified-diff hunks start with @@ -old,len +new,len @@ and show a few lines of context with - for removed lines and + for added ones. git diff and every code-review tool speak this format natively.
Related terms: patch, Git
Discussed in:
- Chapter 7: Pipes, Redirection, and Streams — Comparing Files