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

gx undo [flags]
gx redo

Flags

FlagDescription
--dry-runShow what would be undone without making changes
--historyShow the undo/redo history log

Detection Priority

gx undo checks conditions in this order and acts on the first match:
PriorityConditionUndo ActionEffect
1Merge conflict in progressgit merge --abortReturns to pre-merge state
2Rebase in progressgit rebase --abortReturns to pre-rebase state
3Staged files presentgit reset HEADUnstages all files, changes stay in working tree
4Last reflog entry is amendgit reset --soft HEAD@{1}Restores pre-amend state, changes preserved
5Last reflog entry is merge commitgit reset --hard HEAD~1Removes the merge commit (hard reset)
6Last reflog entry is commitgit reset --soft HEAD~1Soft reset, changes move back to staging

Examples

$ gx undo --dry-run

Detected: commit "add login page" (a1b2c3d, 5 minutes ago)

  Action:  Soft reset to previous commit. Your changes will be preserved in staging.
  Command: git reset --soft HEAD~1

DRY RUN. No changes will be made

  Would run: git reset --soft HEAD~1
  Result:    Soft reset to previous commit. Your changes will be preserved in staging.

Undo History

Every undo is recorded in .git/gx/undo_history.json. View recent history:
$ gx undo --history

Undo/Redo History (last 10):

 #  Time           Action          Description                Status
 1  5 minutes ago  commit          Undo commit "add login"    active
 2  2 hours ago    stage           Undo 3 staged files        redone
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.
$ gx redo

Redoing: Undo commit "add login page"

Proceed with redo? [y/N] y

OK Redone.
Redo performs a git reset --hard to the pre-undo ref. Make sure you don’t have uncommitted work you want to keep.
  • 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
  • Merge commit undo uses --hard reset, which discards changes. Other undo types use --soft reset