{"record":{"id":"c944078bb2fd876a","repo":"jesseduffield/lazygit","slug":"there-s-no-commit-to-amend","errorCode":null,"errorMessage":"There's no commit to amend.","messagePattern":"There's no commit to amend\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/gui/controllers/files_controller.go","lineNumber":1071,"sourceCode":"\t\t\t\t\t}\n\t\t\t\t\treturn nil\n\t\t\t\t},\n\t\t\t\tKeys: menuKey('e'),\n\t\t\t},\n\t\t},\n\t})\n}\n\nfunc (self *FilesController) refresh() error {\n\tself.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}})\n\treturn nil\n}\n\nfunc (self *FilesController) handleAmendCommitPress() error {\n\tdoAmend := func() error {\n\t\treturn self.c.Helpers().WorkingTree.WithEnsureCommittableFiles(func() error {\n\t\t\tif len(self.c.Model().Commits) == 0 {\n\t\t\t\treturn errors.New(self.c.Tr.NoCommitToAmend)\n\t\t\t}\n\n\t\t\treturn self.c.Helpers().AmendHelper.AmendHead()\n\t\t})\n\t}\n\n\tif self.isResolvingConflicts() {\n\t\treturn self.c.Menu(types.CreateMenuOptions{\n\t\t\tTitle:      self.c.Tr.AmendCommitTitle,\n\t\t\tPrompt:     self.c.Tr.AmendCommitWithConflictsMenuPrompt,\n\t\t\tHideCancel: true, // We want the cancel item first, so we add one manually\n\t\t\tItems: []*types.MenuItem{\n\t\t\t\t{\n\t\t\t\t\tLabel: self.c.Tr.Cancel,\n\t\t\t\t\tOnPress: func() error {\n\t\t\t\t\t\treturn nil\n\t\t\t\t\t},\n\t\t\t\t},","sourceCodeStart":1053,"sourceCodeEnd":1089,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/controllers/files_controller.go#L1053-L1089","documentation":"Thrown by FilesController.handleAmendCommitPress when Model().Commits is empty at the moment of amending. Amending rewrites HEAD; with no commits loaded there is no HEAD to amend (empty repository, or the commits model is not populated yet). The check runs inside WithEnsureCommittableFiles so it only fires once there are committable files, meaning the user genuinely tried to amend in a repo whose history is empty.","triggerScenarios":"Pressing shift+A (amend commit) in the files panel of a brand-new repository with staged files but zero commits, i.e. the very first commit does not exist yet.","commonSituations":"Fresh 'git init' repositories where users stage everything then press amend by habit; or a repo whose commits panel has not loaded (huge repo, slow load) though the empty-history case is the real trigger.","solutions":["Make a normal initial commit instead ('c' commit) — amend needs an existing HEAD","If history exists but is not shown, refresh ('r') and confirm the commits panel is populated before amending"],"exampleFix":"# before: empty repo, shift+A errors\ngit add -A && git commit -m 'initial'   # use commit, not amend\n# after: repo has HEAD, amend works\ngit commit --amend --no-edit","handlingStrategy":"validation","validationCode":"// Require a populated commit model before amending:\nif len(model.Commits) == 0 {\n    return errors.New(\"no commit to amend: create an initial commit first\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Hide/disable the amend action in repositories without HEAD","Detect empty history with 'git rev-parse --verify HEAD' in scripts before --amend","Offer plain commit as the fallback in empty repos"],"tags":["git","amend","empty-repo","initial-commit"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}