Skip to main content
gx undo inspects your repo state and automatically determines the right undo operation. It detects merges, rebases, staged files, amended commits, merge commits, and regular commits — then offers to reverse whichever it finds first. gx redo reverses the last undo, restoring your repo to its previous state.

Usage

Flags

Detection Priority

gx undo checks conditions in this order and acts on the first match:

Examples

Undo History

Every undo is recorded in .git/gx/undo_history.json. View recent history:
The history stores pre- and post-state refs, which enables gx redo to safely restore the previous state.

Redo

gx redo reverses the most recent undo. It checks that the repo state has not changed since the undo was performed — if HEAD has moved, redo is blocked with an explanation.
Redo performs a git reset --hard to the pre-undo ref. It will block if the working tree is dirty (uncommitted changes) to prevent accidental data loss.
  • If nothing is detected, gx prints > Nothing to undo.
  • History is capped at 50 entries and stored per-repo in .git/gx/undo_history.json
  • Redo checks that HEAD matches the post-undo ref. If you made commits after undoing, redo will refuse with an explanation
  • Redo blocks if the working tree is dirty to prevent data loss from git reset --hard
  • Reflog detection skips non-matching entries instead of stopping at the first mismatch, improving detection accuracy
  • Merge commit undo uses --hard reset, which discards changes. Other undo types use --soft reset