Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Inspecting History

git diff options

Reference for diff options shared by git diff, log, show and others: --stat, --word-diff, whitespace flags, -U context, algorithms, rename detection and output formats.

The "diff options" are a family of flags shared by every command that can print differences: git diff, git log -p, git show, git format-patch, git stash show and the plumbing diff commands. Learn them once and they work everywhere.

They fall into groups: what to print (a patch, statistics, names, raw data), how to treat whitespace, how much context to show, which algorithm finds the changes, and how renames and moves are detected. Defaults for several of them can be set in the diff.* configuration.

Terminal
git diff --stat
git diff -w --word-diff
git diff -U0 --patience

Try it

Bash Summaries, renames and context

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Whitespace and word-level diffs

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Options go before the revisions and paths, for example git diff <options> <a> <b> -- <path>.

What to output

Option Description
-p, -u, --patch Generate a patch (the default for diff, needed for log and show).
-s, --no-patch Suppress all diff output.
--stat[=<width>[,<name-width>[,<count>]]] A per-file change graph and totals.
--shortstat Only the totals line.
--numstat Added and deleted line counts per file (- for binary), machine friendly.
--dirstat[=<params>] Percentage of change per directory.
--name-only, --name-status File names, optionally with A, M, D, R...
--raw Mode, blob IDs and status per file (the plumbing format).
--summary Extended header info: renames, mode changes, created and deleted files.
--compact-summary Like --stat, with new/deleted/mode flags in the name column.
--patch-with-stat The stat followed by the patch.
-z NUL-terminated output for scripts.
--full-index, --abbrev[=<n>] Print full or shorter blob IDs.
--binary Include a binary patch that git apply can use.

Context and algorithm

Option Description
-U<n>, --unified=<n> Lines of context (default 3).
--inter-hunk-context=<n> Merge hunks that are closer than n lines.
-W, --function-context Show the whole function around each change.
--diff-algorithm=<name> myers (default), minimal, patience, histogram. Shortcuts: --minimal, --patience, --histogram.
--indent-heuristic Slide hunks to nicer boundaries (on by default).

Whitespace

Option Description
-w, --ignore-all-space Ignore all whitespace differences inside lines.
-b, --ignore-space-change Treat runs of whitespace as equal.
--ignore-space-at-eol Ignore trailing whitespace changes.
--ignore-cr-at-eol Ignore a carriage return at line end.
--ignore-blank-lines Ignore changes that only add or remove blank lines.
--check Report whitespace errors and leftover conflict markers on added lines; exits non-zero when found.

Words, renames and moves

Option Description
--word-diff[=<mode>] Show changes inside lines. Modes: color, plain ([-old-]new), porcelain, none.
--word-diff-regex=<regex> What counts as a word.
--color-words[=<regex>] Shorthand for --word-diff=color.
-M[<n>], --find-renames Detect renames (similarity threshold, default 50%).
-C[<n>], --find-copies Also detect copies.
--no-renames Treat a rename as a delete plus an add.
--color-moved[=<mode>] Color blocks of moved lines differently.
--diff-filter=[ACDMRTUXB*] Select files by status (lowercase excludes).
-O<orderfile> Order files by patterns in a file.
-R Reverse the diff.
--relative[=<path>] Show paths relative to a subdirectory and exclude files outside it.

Usage notes

  • --stat is truncated to the terminal width. In pipes it defaults to 80 columns; give widths explicitly (--stat=120) for stable output.
  • Rename detection is on by default for diff, log and show (diff.renames=true). It compares content, so a rename with big edits can appear as delete plus add.
  • -w hides real changes inside strings or in whitespace-significant formats (Python, YAML, Makefiles). Use it for review, not for deciding that two files are the same.
  • Choose an algorithm for confusing diffs. patience and histogram often give cleaner hunks for code with many repeated lines; set it once with git config diff.algorithm histogram.
  • --word-diff=porcelain gives a line-per-chunk format (+, -, space, ~ for line end) meant for tools.
  • --numstat and --raw with -z are the safe formats to parse; avoid scraping --stat.
  • Options belong to the command, not the revision: git log -p --stat combines a patch and statistics for every commit.