gritHEAD → docs/stash
Commands / Making changesMarkdown

grit stash

Save and restore shelved work.

grit stash [-m <msg>] [-u] [-- path…]
grit stash push [-m <msg>] [-u] [-S] [-k] [--hunks <id,...>] [--lines <path:start-end>] [--dry-run] [--pathspec-from-file <file|->] [--pathspec-file-nul] [-- path…]
grit stash list
grit stash show [<n>|<commit>] [--stat] [-p] [-u]
grit stash apply [<n>|<commit>] [--index]
grit stash pop [<n>|<commit>] [--index]
grit stash branch <name> [<n>|<commit>]
grit stash drop [<n>]
grit stash clear [--force] [--dry-run]

Description

Shelve uncommitted changes and restore them later. With no subcommand, grit stash saves local changes (same as grit stash push), resets the working tree and index to HEAD, and records a stash entry compatible with Git's refs/stash format. Skip-worktree paths are not stashed or reset on push, and the bit stays set through pop, matching Git. Unreadable worktree directories produce a warning naming the path; stash still saves readable changes and does not treat files under those directories as deleted. Like Git, dirty content inside a checked-out submodule whose gitlink commit is unchanged does not count as a local change to save (push reports that there is nothing to stash); a submodule whose HEAD moved away from the recorded gitlink is still stashed.

Like Git, stash never signs the commits it records, even when commit.gpgsign is true, so a configured signing program is not run on push.

Pass -- followed by pathspecs (or --pathspec-from-file) on push to stash only matching paths; other staged and unstaged changes stay in place. The stash commit still records the full index on its index parent; the working-tree parent and optional untracked parent are limited to those paths, matching git stash push -- <pathspec>. Attribute pathspecs such as :(attr:myattr) use the same .gitattributes stack as grit log.

Stash indices follow Git: 0 is the newest entry. You can pass an integer or stash@{n}. An all-decimal token is always an index (never a short object id). Any other revision resolves to a stash commit id: apply and branch accept dangling stash commits (for example after drop), and pop accepts a commit id only while that commit is still on the stack.

grit stash pop applies the entry and removes it when there are no conflicts. When applying would leave merge conflicts, the stash entry is kept and the command exits non-zero; conflicting paths are listed. There is no merge to continue: edit the files, mark them resolved with grit add <file>, then remove the kept entry with grit stash drop (or pick a side with grit restore --ours|--theirs <file>). grit stash apply stops the same way but never drops the entry.

apply and pop preserve the exact tracked filename bytes, including literal names beginning with grit+pathhex: and non-UTF-8 names on Unix. If a stashed change would overwrite local edits to that file, the operation fails before changing files and keeps the stash. Conflict paths use reversible grit+pathhex: encoding when needed; Rust callers can recover the original bytes with repo_relpath::storage_bytes.

When a stash was created with -u / --include-untracked, apply and pop refuse to write stashed untracked files onto a path that already exists on disk (visible untracked, ignored, or tracked content you added after stashing). The command exits non-zero, the stash entry is kept, and your existing file bytes are unchanged.

On an interactive terminal (human output, not --json or --markdown), push shows a live Staging line while it hashes local changes and a Checkout line while it resets them, and apply and pop show a Checkout line; nothing is drawn when stderr is not a TTY.

Push, apply, and pop either complete or change nothing. A pop or apply that includes untracked files finishes restoring every path (tracked and untracked) before it writes the index or drops the stash entry; if an object cannot be read (for example because background repack moved it while the command was running), the worktree and index are rolled back and the stash entry stays. Pressing Ctrl+C, or sending SIGTERM or SIGHUP on Unix, while the index or work tree is being updated stops the command with error: operation cancelled; HEAD, the index and the work tree are left as they were, no .git/index.lock is left behind, and the same stash command can simply be run again. This works the same in a Windows console, where Ctrl+Break counts as Ctrl+C. A second interrupt terminates grit at once, without that cleanup; only SIGKILL skips rollback. Staging may leave unreachable loose blobs if you interrupt mid-write; they are harmless.

Options

Option Description
-m, --message Message stored on the stash reflog (push / bare grit stash).
-u, --include-untracked Include untracked files in the stash (not with --hunks / --lines or --staged).
-S, --staged Stash only index changes vs HEAD; unstaged edits on other paths remain (not with -u, --hunks, or --lines).
-k, --keep-index Stash tracked changes but leave the index and worktree matching staged content afterward.
--hunks Stash only listed unstaged hunk ids from grit diff --unstaged --json.
--lines Stash only unstaged line ranges (path:start-end, same as grit add --lines).
--dry-run Preview what would be stashed; no objects, refs, index, or worktree updates.
-n, --limit Cap path lists in --dry-run preview output.
<path>… Limit what is stashed (after --); with --staged, only matching index changes are saved and reset.
--pathspec-from-file Read pathspecs from a file, or - for stdin (same rules as Git).
--pathspec-file-nul With --pathspec-from-file, entries are NUL-separated instead of line-based.
--index On apply / pop, restore the stashed index as well as the worktree. Changes that were unstaged when you stashed come back unstaged, including when nothing was staged at all.
<n> Stash index for show, apply, pop, or drop (default 0).
--stat Show a diffstat in grit stash show (default when -p is not set).
-p, --patch Show the full patch in grit stash show instead of a diffstat.
-u, --include-untracked On show, include untracked files from the stash U parent (same as git stash show -u).
push Save changes explicitly (same flags as bare grit stash).
list List stash entries.
show Show a diffstat or patch for one entry.
apply Apply an entry without removing it.
pop Apply an entry and drop it when clean.
drop Remove an entry without applying it.
branch Create a branch at the stash base commit, check it out, apply with --index (staged changes come back staged, unstaged ones unstaged), and drop the entry on success.
clear Remove every stash entry. Requires --force; without it the command exits non-zero and reports how many entries would be cleared. --dry-run reports the count without deleting.

JSON output

Schema: v1 · stash.push v1 · stash.list v2, v1 · stash.show v1 · stash.apply v2, v1 · stash.pop v1 · stash.drop v2, v1 · stash.branch v2, v1 · stash.clear v1

Pass --json for stable, scripting-friendly output.

grit stash / grit stash push

Partial stash (--hunks / --lines) also includes stashed_hunks and stashed_lines maps (same shape as grit add --json).

Field Type Meaning
oid string Full object id of the stash commit (success object only).
message string Reflog message (for -m, On <branch>: …; otherwise Git-style WIP on …).
mode string all, staged_only, or keep_index. Omitted when all.
dry_run boolean Always true on the preview object; omitted on successful save (false).
paths array of strings Tracked paths that would be stashed (--dry-run preview only).
untracked array of strings Untracked paths in a dry-run preview when -u is set.
stashed_hunks object Map of repository-relative path → hunk id strings stashed (partial --hunks only; same shape as grit add --json). Omitted when empty.
stashed_lines object Map of path → line range labels stashed (partial --lines only). Omitted when empty.
paths array of strings Resolved pathspecs when push was limited with -- path… or --pathspec-from-file. Omitted when empty.
stashed boolean Present and false only on the empty-worktree result.

grit stash list

Field Type Meaning
action string Always "list".
entries array Stash entries, newest first.
entries[].index number Index matching stash@{index}.
entries[].oid string Full stash commit id.
entries[].message string Reflog message.

grit stash show

With --patch, a patch object with the same shape as grit diff is included instead of stat.

Field Type Meaning
index number Stash index shown.
include_untracked boolean Whether -u / --include-untracked was used (omitted when false).
stat object Diffstat summary (when -p is not set).
patch object Full diff outcome (when -p is set).

grit stash branch

When conflicts is true, conflict_paths lists paths with unmerged index entries.

Field Type Meaning
branch string Branch created and checked out.
base string Stash base commit (parent 1 of the W commit).
oid string Stash W commit that was applied.
index number Stash index when the commit was on the stack (omitted for an off-stack commit id).
conflicts boolean Whether merge conflicts remain after apply.
conflict_paths array of strings Conflicted paths when conflicts is true.

grit stash clear

Field Type Meaning
cleared number Stash reflog entries removed or that would be removed.
dry_run boolean True when nothing was deleted (--force missing or --dry-run).

grit stash apply / grit stash pop

When conflicts is true, conflict_paths lists paths with unmerged index entries. On a clean apply or pop the field is omitted.

Pop adds dropped (whether the entry was removed):

Field Type Meaning
oid string Stash W commit id (always set on apply).
index number Stash index when the selector was on the stack (omitted for a bare commit id).
conflicts boolean Whether merge conflicts remain.
index_restored boolean Whether --index was used.
conflict_paths array of strings Paths with unmerged index entries when conflicts is true.
dropped boolean (pop only) Whether the stash entry was removed.

grit stash drop

Field Type Meaning
index number Stash index removed.
oid string Full hex id of the dropped stash W commit (for recovery with grit stash apply <oid>).

Markdown output

Schema: v1 With --markdown, list/apply/pop/drop use bullet lists; show renders the diffstat or patch like other diff commands.

Exit status

Code Meaning
0 Success (success).
1 Command failed (failure).
2 Invalid flags or arguments (usage).

See Exit codes for shared rules and structured --json kind values.

With --json, typed stash failures use the shared error schema. Common kind values include stash_not_found when apply, pop, drop, or show names an index with no entry (for example pop on an empty stack), not_a_repository when the command needs a repository, and lock_held when another process holds .git/index.lock before any stash write. Human messages name the missing index (stash@{n}) or say no stash entries when the stack is empty. Apply and pop that would overwrite local tracked edits or clobber an on-disk untracked file exit 1 without changing the stash entry; --json still carries the error string (no separate kind yet for those cases).

When another process holds .git/index.lock, grit stash, stash push, apply, pop and branch fail with exit 1 (kind lock_held under --json) before writing anything: no stash commit or refs/stash entry is created, and the worktree and index are unchanged. Retry once the other process finishes. If a push fails after refs/stash was updated (for example an I/O error while resetting the worktree), the entry stays on the stash so the saved changes are never only a dangling object.