jesseduffield/lazygit · warning
Creating custom patches is not possible with a diff context
Error message
Creating custom patches is not possible with a diff context size of 0. Increase the context using '%s'.
What it means
CommitFilesController.toggleForPatch (pkg/gui/controllers/commits_files_controller.go) refuses to add/remove files to a custom patch when user config git.diffContextSize is 0. Building a patch needs at least one context line to know where hunk boundaries are, so with zero context lazygit returns the translated NotEnoughContextForCustomPatch action error and suggests the IncreaseContextInDiffView key.
Source
Thrown at pkg/gui/controllers/commits_files_controller.go:449
func (self *CommitFilesController) openDiffTool(node *filetree.CommitFileNode) error {
from, to := self.context().GetFromAndToForDiff()
from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(from)
_, err := self.c.RunSubprocess(self.c.Git().Diff.OpenDiffToolCmdObj(
git_commands.DiffToolCmdOptions{
Filepath: node.GetPath(),
FromCommit: from,
ToCommit: to,
Reverse: reverse,
IsDirectory: !node.IsFile(),
Staged: false,
}))
return err
}
func (self *CommitFilesController) toggleForPatch(selectedNodes []*filetree.CommitFileNode) error {
if self.c.UserConfig().Git.DiffContextSize == 0 {
return fmt.Errorf(self.c.Tr.Actions.NotEnoughContextForCustomPatch,
self.c.UserConfig().Keybinding.Universal.IncreaseContextInDiffView)
}
refName := self.context().GetRef().RefName()
toggle := func() error {
return self.c.WithWaitingStatus(self.c.Tr.UpdatingPatch, func(gocui.Task) error {
selectedNodes = normalisedSelectedCommitFileNodes(selectedNodes)
// Find if any file in the selection is unselected or partially added
adding := lo.SomeBy(selectedNodes, func(node *filetree.CommitFileNode) bool {
return node.SomeFile(func(file *models.CommitFile) bool {
fileStatus := self.c.Git().Patch.PatchBuilder.GetFileStatus(file.Path, refName)
return fileStatus == patch.PART || fileStatus == patch.UNSELECTED
})
})
patchOperationFunction := self.c.Git().Patch.PatchBuilder.RemoveFileView on GitHub (pinned to c477a2959b)
Solutions
- Press the increase-diff-context key (default '}') at least once before toggling patch entries.
- Or set git.diffContextSize to 1 or higher in the user config and restart.
- If a helper script drives lazygit, ensure its config sets a non-zero 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 building custom patches")
} Prevention
- Keep git.diffContextSize >= 1 whenever you use custom patches.
- Learn the '}' key: it raises context in-place when the error appears.
- Scripts driving lazygit should always pin a non-zero context.
When it happens
Trigger: Setting `git.diffContextSize: 0` in the config (or lowering context to 0 with the decrease-context key), then pressing the toggle-patch key (default 'space' in the commit-files view while building a custom patch).
Common situations: Users who set diffContextSize 0 for compact diffs and later try to build a custom patch or move lines between commits; scripts/tests that run with a minimal config.
Related errors
- Staging or unstaging changes is not possible with a diff con
- Discarding changes is not possible with a diff context size
- 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/906a2fd1994e4318.
Report an issue: GitHub.