jesseduffield/lazygit · error

Can't undo while rebasing

Error message

Can't undo while rebasing

What it means

Returned by UndoController.reflogUndo when Git().Status.WorkingTreeState().Any() is true — i.e. a rebase, merge, or cherry-pick is in progress. Undoing reflog actions rewrites refs and resets state, which would collide with the in-progress operation, so undo (press 'z') is refused until the working tree state is clean.

Source

Thrown at pkg/gui/controllers/undo_controller.go:81

			Handler:     self.reflogRedo,
			Description: self.c.Tr.RedoReflog,
			Tooltip:     self.c.Tr.RedoTooltip,
		},
	}

	return bindings
}

func (self *UndoController) Context() types.Context {
	return nil
}

func (self *UndoController) reflogUndo() error {
	undoEnvVars := []string{"GIT_REFLOG_ACTION=[lazygit undo]"}
	undoingStatus := self.c.Tr.UndoingStatus

	if self.c.Git().Status.WorkingTreeState().Any() {
		return errors.New(self.c.Tr.CantUndoWhileRebasing)
	}

	return self.parseReflogForActions(func(counter int, action reflogAction) (bool, error) {
		if counter != 0 {
			return false, nil
		}

		switch action.kind {
		case COMMIT:
			self.c.Confirm(types.ConfirmOpts{
				Title:  self.c.Tr.Actions.Undo,
				Prompt: fmt.Sprintf(self.c.Tr.SoftResetPrompt, utils.ShortHash(action.from)),
				HandleConfirm: func() error {
					self.c.LogAction(self.c.Tr.Actions.Undo)
					return self.c.WithWaitingStatus(undoingStatus, func(gocui.Task) error {
						return self.c.Helpers().Refs.ResetToRef(action.from, "soft", undoEnvVars)
					})
				},

View on GitHub (pinned to c477a2959b)

Solutions

  1. Resolve or abort the in-progress rebase/merge (abort is usually 'a' in the status/commits panel), then undo.
  2. If a previous operation crashed and left stale state, run 'git rebase --abort' / 'git merge --abort' / delete stale state files after verifying with 'git status'.
  3. After the working tree state is clean, retry undo.

Example fix

# before
$ # mid-rebase, pressed undo (z) -> Can't undo while rebasing

# after
$ git rebase --abort
# then press z in lazygit
Defensive patterns

Strategy: validation

Validate before calling

if self.c.Git().Status.WorkingTreeState().Any() {
    // prompt to abort/continue the in-progress operation before undo
}

Prevention

When it happens

Trigger: Pressing undo while .git has an active rebase-merge/merge/cherry-pick/revert state (WorkingTreeState().Any() == true).

Common situations: User hits a conflict mid-rebase and instinctively presses undo; aborting an operation was intended but undo was pressed instead; a background operation left state files behind.

Related errors


AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15). Data as JSON: /api/errors/d16035b64ae3e787. Report an issue: GitHub.