{"record":{"id":"0664cbde78d2e568","repo":"jesseduffield/lazygit","slug":"you-cannot-commit-without-a-commit-message","errorCode":null,"errorMessage":"You cannot commit without a commit message","messagePattern":"You cannot commit without a commit message","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/gui/controllers/commit_message_controller.go","lineNumber":167,"sourceCode":"\t} else if currentIndex == context.NoCommitIndex {\n\t\tself.context().SetHistoryMessage(self.c.Helpers().Commits.JoinCommitMessageAndUnwrappedDescription())\n\t}\n\n\tvalidCommit, err := self.setCommitMessageAtIndex(newIndex)\n\tif validCommit {\n\t\tself.context().SetSelectedIndex(newIndex)\n\t}\n\treturn err\n}\n\n// returns true if the given index is for a valid commit\nfunc (self *CommitMessageController) setCommitMessageAtIndex(index int) (bool, error) {\n\tcommitMessage, err := self.c.Git().Commit.GetCommitMessageFromHistory(index)\n\tif err != nil {\n\t\tif errors.Is(err, git_commands.ErrInvalidCommitIndex) {\n\t\t\treturn false, nil\n\t\t}\n\t\treturn false, errors.New(self.c.Tr.CommitWithoutMessageErr)\n\t}\n\tif self.c.UserConfig().Git.Commit.AutoWrapCommitMessage {\n\t\tcommitMessage = helpers.TryRemoveHardLineBreaks(commitMessage, self.c.UserConfig().Git.Commit.AutoWrapWidth)\n\t}\n\tself.c.Helpers().Commits.SetMessageAndDescriptionInView(commitMessage)\n\treturn true, nil\n}\n\nfunc (self *CommitMessageController) confirm() error {\n\t// The default keybinding for this action is \"<enter>\", which means that we\n\t// also get here when pasting multi-line text that contains newlines. In\n\t// that case we don't want to confirm the commit, but switch to the\n\t// description panel instead so that the rest of the pasted text goes there.\n\t//\n\t// Only do this if the SubmitEditorText command is actually mapped to\n\t// \"<enter>\" (the default). If it's not, we can only hope that it's mapped\n\t// to some ctrl key or fn key, which is unlikely to occur in pasted text.\n\t// And if they mapped some *other* command to \"<enter>\", then we're totally","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/controllers/commit_message_controller.go#L149-L185","documentation":"Thrown by CommitMessageController.setCommitMessageAtIndex when GetCommitMessageFromHistory(index) fails with an error other than ErrInvalidCommitIndex. lazygit tries to recall a previous commit message (from the repository's commit history or message history file) to prefill the commit message panel; any I/O or git failure other than 'index out of range' is reported as this generic 'cannot commit without a commit message' error, which mostly signals that the history source could not be read.","triggerScenarios":"Navigating the commit message history in the commit message panel (up/down through previous messages, or the keybinding that cycles recent commit messages) when reading the underlying history fails — e.g. the .git/COMMIT_EDITMSG or history source is unreadable, or the git invocation errored.","commonSituations":"Corrupted or permission-restricted git metadata, unusual repository layouts, or a race where the history file changed underneath the reader. Rarely seen in normal use.","solutions":["Check repository integrity: 'git fsck' and confirm .git is readable","Simply type a commit message manually; the error only blocks the history-prefill path","If it persists, inspect what GetCommitMessageFromHistory runs (git_commands) and reproduce it from the shell to see the underlying error"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Distinguish the expected sentinel from real read failures before surfacing an error:\nmsg, err := git.Commit.GetCommitMessageFromHistory(index)\nif errors.Is(err, git_commands.ErrInvalidCommitIndex) {\n    return false, nil // out-of-range index: benign\n}\nif err != nil {\n    return false, err // real failure: report the underlying error, not a generic one\n}","typeGuard":null,"tryCatchPattern":"// errors.Is on the sentinel, generic fallback for the rest:\nif err != nil {\n    if errors.Is(err, git_commands.ErrInvalidCommitIndex) {\n        return false, nil\n    }\n    return false, fmt.Errorf(\"reading commit message history: %w\", err)\n}","preventionTips":["Keep .git metadata readable; run 'git fsck' when history reads start failing","Always branch on sentinel errors (errors.Is) instead of collapsing them into one message","Wrap the underlying error (%w) so users can diagnose the real cause"],"tags":["git","commit-message","history","io-error"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}