{"record":{"id":"7db41a29ceef418b","repo":"jesseduffield/lazygit","slug":"cannot-stage-unstage-directory-containing-files-wi","errorCode":null,"errorMessage":"Cannot stage/unstage directory containing files with inline merge conflicts. Please fix up the merge conflicts first","messagePattern":"Cannot stage/unstage directory containing files with inline merge conflicts\\. Please fix up the merge conflicts first","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gui/controllers/files_controller.go","lineNumber":519,"sourceCode":"// callbacks. press() (acting on the selection) and toggleStagedAll() (acting on\n// the whole tree) share this; they differ only in the git commands they run,\n// which is why those are passed in.\n//\n// If any node has unstaged changes we stage the nodes that have them (staging\n// already-staged deleted files/folders would fail); otherwise we unstage all\n// the nodes.\nfunc (self *FilesController) toggleStaged(\n\tnodes []*filetree.FileNode,\n\tstageAction string,\n\tunstageAction string,\n\tstage func(unstagedNodes []*filetree.FileNode) error,\n\tunstage func(nodes []*filetree.FileNode) error,\n) error {\n\tfor _, node := range nodes {\n\t\t// if any files within have inline merge conflicts we can't stage or unstage,\n\t\t// or it'll end up with those >>>>>> lines actually staged\n\t\tif node.GetHasInlineMergeConflicts() {\n\t\t\treturn errors.New(self.c.Tr.ErrStageDirWithInlineMergeConflicts)\n\t\t}\n\t}\n\n\tnodes = normalisedSelectedNodes(nodes)\n\n\tunstagedNodes := filterNodesHaveUnstagedChanges(nodes, self.c.Model().Submodules)\n\n\t// Staging a submodule that only has dirty or untracked content (no new\n\t// commit) is a no-op: the parent repo can't stage that content. When that's\n\t// the only thing that looks stageable, don't stage; fall through to\n\t// unstaging instead. That keeps the toggle symmetric (e.g. a fully-staged\n\t// tree that also contains a dirty submodule still unstages on the next\n\t// press) rather than getting stuck trying to stage the unstageable content.\n\tshouldStage := len(unstagedNodes) > 0\n\tif shouldStage {\n\t\tnoOp, err := self.stagingWouldBeNoOp(unstagedNodes)\n\t\tif err != nil {\n\t\t\treturn err","sourceCodeStart":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/controllers/files_controller.go#L501-L537","documentation":"Thrown by FilesController.toggleStaged when any node in the selection subtree has inline merge-conflict markers. Staging or unstaging a directory containing unresolved conflict files would literally stage the '<<<<<<<'/'======='/'>>>>>>>' marker lines into the index, corrupting the merge resolution, so lazygit refuses until conflicts are resolved.","triggerScenarios":"Pressing 'space' (stage/unstage toggle) on a directory (or multi-node selection) that contains at least one file in a conflicted, unresolved merge/rebase/cherry-pick state.","commonSituations":"Mid-merge with conflicts in several files under one directory; users try to stage the whole directory to 'get it over with' without resolving markers first.","solutions":["Enter the conflicted files (navigate + enter, or the merge-conflicts view) and resolve the markers","Stage each resolved file individually once conflicts are fixed","If you want to take one side wholesale, use the checkout-ours/theirs option on the conflicted file, then stage"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Reject staging when any node in the selection carries conflict markers:\nfor _, node := range nodes {\n    if node.GetHasInlineMergeConflicts() {\n        return errors.New(\"resolve merge conflicts before staging this path\")\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve conflicts file-by-file before any bulk stage operation","Surface conflict badges in file trees so conflicted files are obvious","In automation, abort staging when 'git status' reports unmerged paths under the target"],"tags":["git","staging","merge-conflicts","data-safety"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}