Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Configuration Options

diff.* settings

Reference for diff.* settings: diff.algorithm, renames, colorMoved, context, mnemonicPrefix, tool and per-driver textconv and xfuncname options.

The diff.* settings shape every command that shows changes: git diff, git log -p, git show, git stash show -p and the diffs inside git format-patch. Defaults are fine for small changes; for real projects a better algorithm and move detection make diffs far easier to review.

Plumbing commands such as git diff-tree ignore most of these options, so scripts are unaffected.

Terminal
git config --global diff.algorithm histogram
git config --global diff.colorMoved default
git config --global diff.renames copies
git config --global diff.context 5

Try it

Bash Algorithm 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 Renames and colorMoved

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

Terminal
git config diff.algorithm (myers | minimal | patience | histogram)
git config diff.renames (true | false | copies)
git config diff.colorMoved (no | default | plain | blocks | zebra | dimmed-zebra)
git config diff.context <n>
git config diff.mnemonicPrefix (true | false)
git config diff.noprefix (true | false)
git config diff.tool <tool>
git config diff.external <command>
git config diff.wsErrorHighlight (none | default | all | old,new,context)
git config diff.submodule (short | log | diff)
git config diff.orderFile <file>
git config diff.<driver>.textconv <command>
git config diff.<driver>.xfuncname <regex>
git config diff.<driver>.binary (true | false)
Name Description
diff.algorithm Line-matching algorithm. myers is the default; histogram and patience give clearer diffs when code was moved or similar blocks repeat; minimal is slowest but smallest.
diff.renames Detect renames (default true) or also copies (copies).
diff.colorMoved Color moved blocks differently from added and deleted ones. default is a good choice.
diff.context Lines of context around each change (default 3).
diff.mnemonicPrefix Use i/, w/, c/, o/ instead of a/ and b/ depending on what is compared.
diff.noprefix Remove the a/ and b/ prefixes.
diff.tool Program for git difftool.
diff.external Program run instead of the built-in diff for every file.
diff.wsErrorHighlight Which lines get whitespace errors highlighted.
diff.submodule How to show submodule changes.
diff.orderFile File of glob patterns that decides the order of files in the output.
diff.<driver>.textconv Convert binary files to text before diffing.
diff.<driver>.xfuncname Regex for the "function name" shown in hunk headers.

Errors: an unknown algorithm name makes Git stop with an error that lists the accepted values. diff.renames accepts only a boolean or copies.

Usage notes

  • histogram is a safe upgrade over myers: same speed class, often fewer confusing hunks on code with repeated braces.
  • Renames are detected by content similarity (50% by default). Use -M80% on the command line to demand more.
  • Drivers are attached with .gitattributes (*.pdf diff=pdf) and configured here. textconv output is only used for display, never for applying patches.
  • diff.external replaces the diff for git diff, log -p and show. Use diff.tool with git difftool when you want a side-by-side GUI on demand.
  • Move detection costs time on huge diffs. If a diff feels slow, try without diff.colorMoved.
  • diff.context does not change patches you apply. Narrow context makes patches fragile; leave format-patch at the default.
  • Whitespace: diff.wsErrorHighlight=all marks trailing spaces on removed and unchanged lines too; combine it with core.whitespace.