Skip to main content

Module command_discard

Module command_discard 

Source
Expand description

The commands that can overwrite or delete uncommitted state, read as Git reads them. What: Which regions of git checkout, git switch, git restore, git rm, git mv, git checkout-index, git read-tree and the --abort forms of merge, rebase, cherry-pick, revert and am can overwrite or delete uncommitted state. Why: The linked-worktree policy confines such commands: it rejects them in the main worktree and, once the worktree holds uncommitted state, in a linked worktree too. Each region is read as Git 2.56.0 reads it, so a spelling Git accepts as --force is not missed and a value that looks like a flag is not mistaken for one. Gotcha: Where Git itself refuses the region the answer is the refusal; the caller lets Git say so.

In TS you’d write (pseudocode):

// checkoutDiscard(['--', 'a.txt']) === 'overwrites'; checkoutDiscard(['topic']) === 'moves-head'

Enums§

Discard
What: What a region can do to uncommitted state. An enum is a closed set of named alternatives. Why: A region that overwrites is judged by the worktree kind; one that only moves HEAD loses nothing unless local changes exist, so it is judged by them alone.

Functions§

abort_discard
What: Read a region of merge, rebase, cherry-pick, revert or am for --abort. Why: Aborting restores the pre-operation index and worktree, discarding everything done since, including the hand edits that resolved a conflict. --ab is the shortest prefix no sibling option shares.
checkout_discard
What: Read a git checkout region. Result<A, B> is “either success A or failure B”. Why: --force, --patch, --ours, --theirs, a path list (--, --pathspec-from-file, or a tree-ish followed by paths) overwrite files; a lone name moves HEAD or, when it is a file, overwrites it, so it counts as a HEAD move that is rejected once local changes exist.
force_discard
What: Read a git rm, git mv or git checkout-index region. Why: Each refuses to overwrite or delete a modified file unless forced; -f and --force are the only way these commands discard. --fo is the shortest prefix of --force in all three.
read_tree_discard
What: Read a git read-tree region. Why: --reset replaces the index and, with -u, the worktree, dropping every unmerged and local entry. --res is the shortest prefix that --recurse-submodules does not share.
restore_discard
What: Read a git restore region. Why: Every form writes worktree files, the index, or both; only a request for usage text writes nothing.
restores_index_only
What: Whether a git restore region touches the index only. Why: --staged alone unstages and leaves the files, so the guidance differs from a restore of file content; --worktree beside it brings the files back in. --st and --w are the shortest unambiguous prefixes.
switch_discard
What: Read a git switch region. Why: --force and --discard-changes throw local changes away; any named target moves HEAD.