jesseduffield/lazygit · warning
You have local modifications for the file(s) you are trying…
Error message
You have local modifications for the file(s) you are trying to check out. You need to stash or discard these first.
What it means
Thrown by CommitFilesController.checkout when checking out a file (or directory) from a commit would overwrite locally modified files. helpers.AnyTrackedFilesInPathExceptSubmodules finds tracked files under the node's path that currently have modifications in the working tree; git checkout of the historical version would clobber them, so lazygit demands you stash or discard first.
Solutions
- Stash your changes ('s' menu in the files panel), check out the file, then pop the stash and resolve
- Discard the local modifications ('d' on the file) if they are not needed, then check out
- Commit the local changes first so they are recoverable, then check out the historical version
Example fix
# before: file has local edits, checkout from commit errors # after git stash git checkout <commit> -- path/to/file git stash pop
Defensive patterns
Strategy: validation
Validate before calling
// Mirror the controller's check before checking out paths from a commit:
if helpers.AnyTrackedFilesInPathExceptSubmodules(node.GetPath(), model.Files, model.Submodules) {
return fmt.Errorf("stash or discard local modifications to %s first", node.GetPath())
} Prevention
- Check for local modifications under the target path before 'git checkout <commit> -- <path>'
- Stash before restoring historical file versions
- In automation, prefer 'git checkout' only on paths verified clean via 'git status --porcelain -- <path>'
When it happens
Trigger: In the commit-files view (files of a selected commit), pressing the checkout-file key ('c' / space depending on keybindings) on a path that overlaps files with uncommitted local changes.
Common situations: Trying to restore an old version of a file you are mid-edit on, or checking out a whole directory from a commit while the working tree is dirty in that directory.
Related errors
- Cannot stage/unstage directory containing files with inline…
- A remote named ' ' does not exist
- Base commit is not in current view
- Branch } is checked out by worktree }
- Can't redo while rebasing
AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15).
Data as JSON: /api/errors/a216897374bc7f2e.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/gui/controllers/commits_files_controller.go:318
return self.c.Menu(types.CreateMenuOptions{
Title: self.c.Tr.CopyToClipboardMenu,
Items: []*types.MenuItem{
copyNameItem,
copyRelativePathItem,
copyAbsolutePathItem,
copyFileDiffItem,
copyAllDiff,
copyFileContentItem,
},
})
}
func (self *CommitFilesController) checkout(node *filetree.CommitFileNode) error {
hasModifiedFiles := helpers.AnyTrackedFilesInPathExceptSubmodules(node.GetPath(),
self.c.Model().Files, self.c.Model().Submodules)
if hasModifiedFiles {
return errors.New(self.c.Tr.CannotCheckoutWithModifiedFilesErr)
}
self.c.LogAction(self.c.Tr.Actions.CheckoutFile)
_, to := self.context().GetFromAndToForDiff()
if err := self.c.Git().WorkingTree.CheckoutFile(to, node.GetPath()); err != nil {
return err
}
self.c.Refresh(types.RefreshOptions{})
return nil
}
func (self *CommitFilesController) discard(selectedNodes []*filetree.CommitFileNode) error {
prompt := lo.Ternary(self.c.Git().Patch.PatchBuilder.Active(),
self.c.Tr.DiscardFileChangesPromptResetPatch,
self.c.Tr.DiscardFileChangesPrompt)
self.c.Confirm(types.ConfirmOpts{View on GitHub (pinned to c477a2959b)