jesseduffield/lazygit · warning
Discarding changes is not possible with a diff context size
Error message
Discarding changes is not possible with a diff context size of 0. Increase the context using '%s'.
What it means
StagingController.DiscardSelection (pkg/gui/controllers/staging_controller.go) discards the selected lines of the unstaged/staged diff; like ToggleStaged it hard-fails when git.diffContextSize is 0 because hunk reconstruction is impossible, returning NotEnoughContextToDiscard with the increase-context key hint.
Source
Thrown at pkg/gui/controllers/staging_controller.go:215
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) },
})
}
func (self *StagingController) applySelectionAndRefresh(reverse bool) error {
if err := self.applySelection(reverse); err != nil {
return err
}
// Block input until the refresh has landed: it rebuilds the staging panel
// and moves the selection to the next stageable change, and a quick secondView on GitHub (pinned to c477a2959b)
Solutions
- Increase the diff context with '}' (default) and retry the discard.
- Or persist git.diffContextSize >= 1 in the user config.
- If discarding the whole file is acceptable, use the files-panel discard instead.
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 discarding selected lines")
} Prevention
- Raise context with '}' before destructive line-level discards.
- Keep a non-zero default in the config to avoid surprises.
When it happens
Trigger: diffContextSize == 0 in the staging panel and the user presses the discard-selection key (default 'd') on selected lines; the check runs before the discard confirmation dialog.
Common situations: Same root cause as 157: zero-context diff preference colliding with line-level operations; especially surprising because discard is destructive and users expect the confirm dialog, not a config error.
Related errors
- Staging or unstaging changes is not possible with a diff con
- Creating custom patches is not possible with a diff context
- Feature not available for users using GPG. If you are using
- Feature not available for users using GPG. If you are using
- Unsupported git service
AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15).
Data as JSON: /api/errors/5637bd42890b61f8.
Report an issue: GitHub.