{"record":{"id":"5637bd42890b61f8","repo":"jesseduffield/lazygit","slug":"discarding-changes-is-not-possible-with-a-diff-con","errorCode":null,"errorMessage":"Discarding changes is not possible with a diff context size of 0. Increase the context using '%s'.","messagePattern":"Discarding changes is not possible with a diff context size of 0\\. Increase the context using '(.+?)'\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/gui/controllers/staging_controller.go","lineNumber":215,"sourceCode":"\tif self.otherContext.GetState() != nil {\n\t\tself.c.Context().Push(self.otherContext, types.OnFocusOpts{})\n\t}\n\n\treturn nil\n}\n\nfunc (self *StagingController) ToggleStaged() error {\n\tif self.c.UserConfig().Git.DiffContextSize == 0 {\n\t\treturn fmt.Errorf(self.c.Tr.Actions.NotEnoughContextToStage,\n\t\t\tself.c.UserConfig().Keybinding.Universal.IncreaseContextInDiffView)\n\t}\n\n\treturn self.applySelectionAndRefresh(self.staged)\n}\n\nfunc (self *StagingController) DiscardSelection() error {\n\tif self.c.UserConfig().Git.DiffContextSize == 0 {\n\t\treturn fmt.Errorf(self.c.Tr.Actions.NotEnoughContextToDiscard,\n\t\t\tself.c.UserConfig().Keybinding.Universal.IncreaseContextInDiffView)\n\t}\n\n\treturn self.c.ConfirmIf(!self.staged && !self.c.UserConfig().Gui.SkipDiscardChangeWarning,\n\t\ttypes.ConfirmOpts{\n\t\t\tTitle:         self.c.Tr.DiscardChangeTitle,\n\t\t\tPrompt:        self.c.Tr.DiscardChangePrompt,\n\t\t\tHandleConfirm: func() error { return self.applySelectionAndRefresh(true) },\n\t\t})\n}\n\nfunc (self *StagingController) applySelectionAndRefresh(reverse bool) error {\n\tif err := self.applySelection(reverse); err != nil {\n\t\treturn err\n\t}\n\n\t// Block input until the refresh has landed: it rebuilds the staging panel\n\t// and moves the selection to the next stageable change, and a quick second","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/controllers/staging_controller.go#L197-L233","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before (user config.yml)\ngit:\n  diffContextSize: 0\n\n# after\ngit:\n  diffContextSize: 3","handlingStrategy":"validation","validationCode":"if cfg.Git.DiffContextSize == 0 {\n\treturn errors.New(\"raise git.diffContextSize before discarding selected lines\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Raise context with '}' before destructive line-level discards.","Keep a non-zero default in the config to avoid surprises."],"tags":["config","staging","discard","diff-context"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}