{"record":{"id":"a216897374bc7f2e","repo":"jesseduffield/lazygit","slug":"you-have-local-modifications-for-the-file-s-you-a","errorCode":null,"errorMessage":"You have local modifications for the file(s) you are trying to check out. You need to stash or discard these first.","messagePattern":"You have local modifications for the file\\(s\\) you are trying to check out\\. You need to stash or discard these first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/gui/controllers/commits_files_controller.go","lineNumber":318,"sourceCode":"\n\treturn self.c.Menu(types.CreateMenuOptions{\n\t\tTitle: self.c.Tr.CopyToClipboardMenu,\n\t\tItems: []*types.MenuItem{\n\t\t\tcopyNameItem,\n\t\t\tcopyRelativePathItem,\n\t\t\tcopyAbsolutePathItem,\n\t\t\tcopyFileDiffItem,\n\t\t\tcopyAllDiff,\n\t\t\tcopyFileContentItem,\n\t\t},\n\t})\n}\n\nfunc (self *CommitFilesController) checkout(node *filetree.CommitFileNode) error {\n\thasModifiedFiles := helpers.AnyTrackedFilesInPathExceptSubmodules(node.GetPath(),\n\t\tself.c.Model().Files, self.c.Model().Submodules)\n\tif hasModifiedFiles {\n\t\treturn errors.New(self.c.Tr.CannotCheckoutWithModifiedFilesErr)\n\t}\n\n\tself.c.LogAction(self.c.Tr.Actions.CheckoutFile)\n\t_, to := self.context().GetFromAndToForDiff()\n\tif err := self.c.Git().WorkingTree.CheckoutFile(to, node.GetPath()); err != nil {\n\t\treturn err\n\t}\n\n\tself.c.Refresh(types.RefreshOptions{})\n\treturn nil\n}\n\nfunc (self *CommitFilesController) discard(selectedNodes []*filetree.CommitFileNode) error {\n\tprompt := lo.Ternary(self.c.Git().Patch.PatchBuilder.Active(),\n\t\tself.c.Tr.DiscardFileChangesPromptResetPatch,\n\t\tself.c.Tr.DiscardFileChangesPrompt)\n\n\tself.c.Confirm(types.ConfirmOpts{","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/controllers/commits_files_controller.go#L300-L336","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before: file has local edits, checkout from commit errors\n# after\ngit stash\ngit checkout <commit> -- path/to/file\ngit stash pop","handlingStrategy":"validation","validationCode":"// Mirror the controller's check before checking out paths from a commit:\nif helpers.AnyTrackedFilesInPathExceptSubmodules(node.GetPath(), model.Files, model.Submodules) {\n    return fmt.Errorf(\"stash or discard local modifications to %s first\", node.GetPath())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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>'"],"tags":["git","checkout-file","dirty-working-tree","data-safety"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}