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
enumis a closed set of named alternatives. Why: A region that overwrites is judged by the worktree kind; one that only movesHEADloses nothing unless local changes exist, so it is judged by them alone.
Functions§
- abort_
discard - What:
Read a region of
merge,rebase,cherry-pick,revertoramfor--abort. Why: Aborting restores the pre-operation index and worktree, discarding everything done since, including the hand edits that resolved a conflict.--abis the shortest prefix no sibling option shares. - checkout_
discard - What:
Read a
git checkoutregion.Result<A, B>is “either successAor failureB”. Why:--force,--patch,--ours,--theirs, a path list (--,--pathspec-from-file, or a tree-ish followed by paths) overwrite files; a lone name movesHEADor, when it is a file, overwrites it, so it counts as aHEADmove that is rejected once local changes exist. - force_
discard - What:
Read a
git rm,git mvorgit checkout-indexregion. Why: Each refuses to overwrite or delete a modified file unless forced;-fand--forceare the only way these commands discard.--fois the shortest prefix of--forcein all three. - read_
tree_ discard - What:
Read a
git read-treeregion. Why:--resetreplaces the index and, with-u, the worktree, dropping every unmerged and local entry.--resis the shortest prefix that--recurse-submodulesdoes not share. - restore_
discard - What:
Read a
git restoreregion. 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 restoreregion touches the index only. Why:--stagedalone unstages and leaves the files, so the guidance differs from a restore of file content;--worktreebeside it brings the files back in.--stand--ware the shortest unambiguous prefixes. - switch_
discard - What:
Read a
git switchregion. Why:--forceand--discard-changesthrow local changes away; any named target movesHEAD.