jesseduffield/lazygit · warning

Staging or unstaging changes is not possible with a diff con

Error message

Staging or unstaging changes is not possible with a diff context size of 0. Increase the context using '%s'.

What it means

StagingController.ToggleStaged (pkg/gui/controllers/staging_controller.go) stage-stages or unstages the selected lines/hunks; with git.diffContextSize == 0 lazygit cannot map the selection back to hunks, so it refuses with the translated NotEnoughContextToStage message and points at the IncreaseContextInDiffView key.

Source

Thrown at pkg/gui/controllers/staging_controller.go:206

		if state.SelectingHunkEnabledByUser() {
			return self.c.Tr.SelectLineByLine
		}
	}

	return self.c.Tr.ReturnToFilesPanel
}

func (self *StagingController) TogglePanel() error {
	if self.otherContext.GetState() != nil {
		self.c.Context().Push(self.otherContext, types.OnFocusOpts{})
	}

	return nil
}

func (self *StagingController) ToggleStaged() error {
	if self.c.UserConfig().Git.DiffContextSize == 0 {
		return fmt.Errorf(self.c.Tr.Actions.NotEnoughContextToStage,
			self.c.UserConfig().Keybinding.Universal.IncreaseContextInDiffView)
	}

	return self.applySelectionAndRefresh(self.staged)
}

func (self *StagingController) DiscardSelection() error {
	if self.c.UserConfig().Git.DiffContextSize == 0 {
		return fmt.Errorf(self.c.Tr.Actions.NotEnoughContextToDiscard,
			self.c.UserConfig().Keybinding.Universal.IncreaseContextInDiffView)
	}

	return self.c.ConfirmIf(!self.staged && !self.c.UserConfig().Gui.SkipDiscardChangeWarning,
		types.ConfirmOpts{
			Title:         self.c.Tr.DiscardChangeTitle,
			Prompt:        self.c.Tr.DiscardChangePrompt,
			HandleConfirm: func() error { return self.applySelectionAndRefresh(true) },
		})

View on GitHub (pinned to c477a2959b)

Solutions

  1. Press the increase-context key (default '}') once or more before toggling staged lines.
  2. Or set git.diffContextSize to >= 1 in the user config.
  3. As a workaround use whole-file staging (stage all) which does not depend on context.

Example fix

# before (user config.yml)
git:
  diffContextSize: 0

# after
git:
  diffContextSize: 3
Defensive patterns

Strategy: validation

Validate before calling

if cfg.Git.DiffContextSize == 0 {
	return errors.New("raise git.diffContextSize before line-level staging")
}

Prevention

When it happens

Trigger: diffContextSize reduced to 0 (config `git.diffContextSize: 0` or repeated '{' presses) while in the staging panel, then pressing the stage-selection toggle (default 'space').

Common situations: Users preferring zero-context diffs for reading also using line-level staging; configs copied from minimal setups; after pressing '{' several times the counter in the status line is easy to miss.

Related errors


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