Skip to content
Everyday Git

Reset, restore and clean

The three commands that destroy the most work, and what GitAegis captures before each.

GitAegis
The GitAegis Operation Preview drawer for a hard reset, showing the operation's intent, a Destructive risk badge, the recovery capsule that will be taken first and what it covers, and the rollback that will be available afterwards.
The Operation Preview drawer: the intent, the risk, the capsule that will be taken before anything runs, and the way back. The exact command list sits further down the same drawer.

The classification, first

Reset, restore and clean, classified by what each one destroys
OperationRiskCaptured first
Reset --soft, --mixedcautionLight checkpoint: refs, HEAD, index, patches
Reset --harddestructiveStandard capsule, untracked files included
Restore --stagedsafeNothing
Restore the working treecautionLight checkpoint: refs, HEAD, index, patches
CleandestructiveStandard capsule, untracked files included
Discard (file, hunk or lines)destructiveStandard capsule, untracked files included
The Operation Preview header for a hard reset, showing the intent line and a Destructive risk badge.
The classification is on the plan, in a word, before anything runs.

Reset

Each mode is labelled with what it does to the index and to the working tree, in plain words, and the plan computes the consequences rather than describing the flag. It walks your current tip against every other ref and lists (by oid and subject) the commits that would stop being reachable. For a hard reset it additionally enumerates every file with uncommitted changes that is about to be overwritten, and gives you the count in the summary.

A hard reset also states what it does not touch: untracked files stay on disk. And it offers two alternatives, one of them marked as the recommendation: revert the commits instead, which is safe for shared history because nothing becomes unreachable, or move the tip to a new branch first so the commits keep a name.

Where the branch has an upstream, the plan closes with the remote arithmetic: how far ahead and behind you will be afterwards, and the reminder that publishing a rewritten tip needs a force push, which is a separate previewed operation.

Restore

Restoring the index alone is safe. Index and worktree are reset from HEAD for those paths and nothing uncommitted is lost. Restoring the working tree discards uncommitted work on the paths you named, so it is caution, the plan lists every path it will overwrite, and the discarded content is preserved in the checkpoint’s patches. The rollback step is literal: re-apply the discarded changes from the checkpoint patch.

Clean

Clean is always destructive, because it deletes files that exist nowhere else. The plan enumerates them: every untracked file it will remove, and separately the count of ignored files, with the summary saying whether those are included or kept.

planned commands
# untracked files and directories
git clean -f -d
# only when you explicitly include ignored files
git clean -f -d -x
Including ignored files is a separate, explicitly labelled choice. That is where your .env lives.

The standard capsule taken first includes the untracked archive, which is what makes the rollback step real: restore the deleted files from the checkpoint’s untracked archive.

What the capsule holds, and where it stops

A standard capsule captures refs, HEAD, the reflogs, the binary index, staged and working patches, Git’s in-progress operation state, a sanitised copy of the local config as evidence, an archive of your untracked files, and a bundle. Every entry is checksummed with SHA-256, and a restore re-verifies all of them before it applies anything.

Two size limits, recorded rather than hidden

A single untracked file larger than 32 MiB, or any path that would push the archive past 128 MiB in total, is skipped, and the skip is written into the capsule’s manifest so you can see what was left out instead of discovering it during a restore.

These three commands cannot be cancelled mid-run

Reset, restore and clean are dispatched as non-cancellable steps. Once Git has the command, the app does not pretend it can stop it; the capsule taken beforehand is the recovery path, not a cancel button.

30-day trial · No card required

A recovery capsule before every risky Git operation.

You see the exact commands before they run, and the operation is refused if the capsule cannot be written.

Requires Git 2.38.0 or newer, already installed.

Every risky operation, in this order

  1. Previewthe exact commands, shown before anything runs
  2. Capsulerefs, index, staged and working changes, untracked files, operation state: written to disk first
  3. Executethe commands as shown, or not at all
  4. Journalplan, commands, capsule id, outcome
No capsule, no operation. Restore plans, previews, and takes its own capsule.