Discard an unstaged file edit
#restore --worktree restores the working file from the index by default. The unstaged content is overwritten.
Fragment
Effect: working tree changes. Ordinary unstaged content may have no recoverable Git object.
Reference
Inspect, save, combine and recover work with clear command effects.
Modern Git CLI, including switch and restore (Git 2.23+). Independent examples use illustrative paths and branch names. Inspect status and diffs before changing files or history. Commands below are reference material, not executed by this guide.
restore --worktree restores the working file from the index by default. The unstaged content is overwritten.
Fragment
Effect: working tree changes. Ordinary unstaged content may have no recoverable Git object.
--source chooses the source snapshot. Without --staged, this restores the working file without updating the index.
Fragment
revert records an inverse change while retaining the original history. Later edits may cause conflicts.
Fragment
Effect: new commit. Reverting a merge needs a deliberate mainline-parent choice.
reset --soft moves the current branch/HEAD to a commit but leaves the index and working tree unchanged.
Fragment
Previously committed changes are now staged relative to the earlier HEAD. This rewrites the branch.
The default mixed reset moves HEAD and resets the index to that commit. Working files keep their content.
Fragment
Effect: branch and index change; working edits remain. This differs from path-only git reset -- file, which does not move HEAD.
reset --hard moves HEAD and resets both the index and tracked working files to the target. Untracked paths obstructing tracked writes may also be removed.
Fragment
Uncommitted work can be lost. This is not a general cleanup or undo button.
reflog records local ref movements. Inspect an entry and create a rescue branch to keep the commit reachable.
Fragment
Reflogs expire and are local; they are not a backup of arbitrary uncommitted files.