Description
With no argument, shows every uncommitted change: the working tree and index together, compared with the last commit (HEAD). Pass --staged to compare only the index to HEAD (staged changes). Pass --unstaged to compare only the working tree to the index (changes not yet staged). Pass --against <ref> to compare the working tree to another ref’s tree instead of HEAD (useful for “what changed since main?” while keeping a single commit argument as “show this commit’s patch”). Untracked paths are not diff entries—they appear only in grit status. When a tracked path lives under a worktree directory grit cannot read (for example permission denied), grit warns with the path and continues with the rest of the diff; pathspecs limit the scan so unreadable directories outside the selection are not touched.
Symlinks are compared using the bytes of their link targets, including links to directories and missing paths. Clean filters and line-ending conversion do not apply to link targets. Serial and parallel scans produce the same changes, including on large worktrees; an unchanged symlink does not make a clean tree dirty. With core.symlinks=false, regular files checked out as symlink placeholders retain the link mode recorded in the index.
With one commit, shows the change that commit introduced (its first parent’s tree against its own tree). Commit, range, staged, and unstaged diffs detect renames by default (Git -M50): a move with small edits appears as one renamed file instead of a full delete and add. With two commits, or a two-dot range such as A..B, shows the tree diff between those commits with the same rename detection. A three-dot range A...B diffs from the merge base of A and B to B. When many add/delete candidates remain after exact and basename pairing, inexact rename detection may be skipped because of diff.renameLimit; grit then prints a one-line notice on stderr with the candidate counts, the configured limit, and a suggested limit to retry with (grit -c diff.renameLimit=<n>). JSON and Markdown output are unchanged.
Pass one or more paths after -- (or as trailing arguments when unambiguous) to limit any diff form to those paths—the same pathspec rules as grit log. For commit and tree diffs, that limit is applied before rename detection, so a pathspec that matches only one side of a move is reported as an add or delete, same as Git. Pathspec magic works as in Git, including attribute selection from .gitattributes: grit diff -- ':(attr:diff=rust)' limits the diff to files with diff=rust, and ':(exclude,attr:-diff)' drops files marked -diff. A single positional argument that is neither a revision nor a range is still treated as a worktree path for unstaged changes (grit diff a.txt). If paths after -- or entries from --pathspec-from-file are supplied, an unknown revision is reported as a revision error. With two positional arguments, both are revisions (tree diff); a path limit requires -- (for example grit diff HEAD~1 HEAD -- f) or the commit known-path form when the second token names a file in the repo (grit diff HEAD f).
Each file starts with its path (UTF-8 names print literally; C-quoted only when the name contains control characters, unless core.quotepath=true), and each hunk with its position. Lines have two number columns, the line number before and after the change. In a terminal, removed lines are red, added lines are green, and the words that changed within a line are highlighted when the diff touches at most 64 changed files; larger tree and commit-range diffs stay line-level for throughput. When the output isn't a terminal, or NO_COLOR is set, lines are marked with - and + instead. --json and --markdown use line-level hunks only (no word-level emphasis segments) so large commit-range diffs stay fast. Tree and commit diffs that change 16 or more files honor the global --threads flag and index.threads when loading blobs and computing line diffs; smaller ones run on one thread, which is faster than starting workers. Three lines of unchanged context are shown around each change. Binary files print Binary file differs when the blob changed (mode-only binary changes show mode lines only).
<commit> can be anything that names a commit: a full or short commit id, a branch or tag name, or an expression like HEAD~2.
In a shallow clone, a commit listed in .git/shallow is diffed like a root (against the empty tree), even when its object still names a parent that was not fetched.
Options
| Option | Description |
|---|---|
-p, --patch |
Full patch (the default). Mutually exclusive with the other format flags below. |
--stat |
Per-file change counts with +/- bars and a summary line (like git diff --stat). Mutually exclusive with the other format flags below. |
--numstat |
Machine-readable insertions<TAB>deletions<TAB>path lines (-<TAB>- for binary). |
--shortstat |
Only the summary line (N files changed, …). |
--name-only |
Changed paths, one per line. |
--name-status |
Status letter and path(s) per line (M, A, R100<TAB>old<TAB>new, …). |
--patch-text |
Git-apply-compatible unified patch on stdout (git diff --binary shape): index lines carry abbreviated preimage and postimage blob ids (including unstaged worktree content, hashed at render time), and binary files appear as GIT binary patch sections so git apply --index reproduces them. Human output only; not combinable with --json or --markdown. |
-M, --find-renames[=<n>] |
Detect renames (default similarity 50). Long form requires = when a threshold is given. |
--no-renames |
Do not detect renames. |
--diff-algorithm <algo> |
Line diff algorithm (myers, minimal, patience, histogram). |
--diff-filter <letters> |
Limit to change types (A added, D deleted, M modified, R renamed, …). |
-w, --ignore-all-space |
Ignore whitespace when comparing lines. |
-b, --ignore-space-change |
Ignore changes in the amount of whitespace. |
--ignore-blank-lines |
Ignore changes whose lines are all blank. |
-U, --unified <n> |
Lines of context around each hunk when the output is a patch (bare -U means 3). |
-M, --find-renames[=<n>] |
Detect renames; optional similarity threshold (50 default, or 50%). Attached -M30 is accepted. |
--no-renames |
Do not detect renames (show separate delete and add entries). |
--diff-algorithm <algo> |
Line diff algorithm (myers, patience, histogram, …); overrides diff.algorithm. |
--diff-filter <letters> |
Limit output to change types (A added, D deleted, M modified, R renamed, …). |
-w, --ignore-all-space |
Ignore whitespace when comparing lines. |
-b, --ignore-space-change |
Ignore changes in the amount of whitespace. |
--ignore-blank-lines |
Ignore changes whose lines are all blank. |
-W, --function-context |
Expand patch hunks to enclosing function boundaries (Git -W). |
-p, --patch |
Unified patch output (default when no other format flag is set). |
--exit-code |
Exit with status 1 when there are changes (for scripts); 0 when clean. |
--quiet |
Print nothing; implies --exit-code. |
--staged, -S |
Staged changes only (index vs HEAD). Cannot be combined with --unstaged, commit arguments, or --against. Optional path limits after -- are allowed. |
--unstaged |
Unstaged changes only (worktree vs index). Cannot be combined with --staged, commit arguments, or --against. Optional path limits after -- are allowed. |
--against <ref> |
Compare the worktree to <ref>’s tree instead of HEAD. No commit arguments. Optional path limits after -- are allowed. |
--no-index |
Compare two filesystem paths without a repository: two files, two directories (recursive), or a file and a directory (compared with directory/<file name>, as Git does). Takes exactly two paths and cannot be combined with --staged, --unstaged, --against or commits. Exits 1 when they differ, as with --exit-code. |
--exit-code |
Exit with status 1 when there are changes and 0 when there are none; errors exit 2. |
--quiet |
Print nothing and exit as with --exit-code. |
<commit> |
One commit (that commit’s patch), two commits (tree diff), or a range A..B / A...B. Omit for uncommitted changes. |
--pathspec-from-file <file|-> |
Read pathspecs from a file (- for stdin), in addition to argv paths after --. |
--pathspec-file-nul |
--pathspec-from-file entries are NUL-separated. |
<path>… |
After --, limit the diff to these paths (all forms above, including --staged). |
JSON output
Schema: v1
Pass --json for stable, scripting-friendly output:
| Field | Type | Meaning |
|---|---|---|
changed |
boolean | Whether any selected change exists (matches --exit-code / --quiet). |
files |
array | Changed files (see nested fields below). |
totals |
object | Present for --stat, --numstat, and --shortstat: files_changed, insertions, deletions. |
changed |
boolean | Whether any change was selected; the same answer --exit-code gives as an exit status. |
Each files[] entry includes path, status, binary, optional old_path (renames), optional similarity (0–100 on renames/copies), optional combined_status (per-parent combined letters such as MM or DD on merge --cc / --name-status output; omitted on ordinary two-tree diffs), optional stat ({ "insertions", "deletions" } when line counts were computed; omitted when binary is true), optional old_size / new_size (byte lengths on each side when binary is true, matching --stat’s Bin old -> new bytes line), optional old_mode / new_mode, optional old_encoding_lossy / new_encoding_lossy, and hunks only for the default patch format.
Nested fields include files[].status (added, modified, deleted, renamed, and so on; type_changed, Git's raw T, when a path switches between a regular file, a symlink and a submodule, reported the same way for unstaged, staged, worktree-vs-commit and commit-to-commit diffs, while a permission-only change stays modified), optional files[].old_path when status is renamed, hunks[].old_start / new_start / old_lines / new_lines, optional hunks[].id (twelve lowercase hex characters; present on --staged and --unstaged patch JSON for stable hunk selection), optional hunks[].index (0-based hunk index within the file; same scopes as id), optional hunks[].context (the @@ function-name suffix from the path's diff driver, or the enclosing definition when -W / --function-context is set), hunks[].lines[].kind (context, add, or del), line numbers on old and new, a compact text string per line (or segments with optional emphasis only when intra-line word highlights are present), and no_newline_at_eof when that side lacks a trailing newline (Git’s \ No newline at end of file). JSON is written in compact form (no pretty-printing). When files[].binary is true, hunks is always an empty array — blob bytes are never included in JSON (use human or --markdown output for the “Binary file differs” note). For unstaged and other worktree-sourced sides, line text is normalized to repository form (.gitattributes / core.autocrlf) before diffing, so trailing \r from CRLF checkouts does not appear in line text. Commit and staged diffs compare stored blobs and may still show carriage returns when the on-disk object bytes differ. When file bytes are not valid UTF-8 and the file is treated as text, old_encoding_lossy or new_encoding_lossy is true and non-UTF-8 bytes appear as U+FFFD in text fields. Unstaged gitlinks honor Git's submodule ignore settings (diff.ignoreSubmodules, submodule.<name>.ignore, .gitmodules ignore); --staged omits gitlinks only when ignore is all (index-vs-HEAD OID compare).
Markdown output
Schema: v1
Pass --markdown for one section per changed file: a level-2 heading, then metadata lines (**status:**, and **old_mode:** / **new_mode:** when the git mode changed), then a diff-fenced unified patch when there are text hunks (binary files note Binary file differs. when content changed). Mode-only or rename-only changes omit the fence when the patch would be empty.
Exit status
| Code | Meaning |
|---|---|
0 |
No changes selected, or success without --exit-code / --quiet. |
1 |
Changes exist when --exit-code or --quiet is set (failure). |
2 |
Invalid flags or diff error while --exit-code / --quiet is set (usage). |
See Exit codes for the full table.