mislav/hub · warning

unable to select a comment character that is not used in the

Error message

unable to select a comment character that is not used in the current message

What it means

CommentChar() determines git's core.commentChar, and when it's set to "auto", the library scans the commit message for a character not used at line starts, throwing this error if every candidate collides. It means git (or the library) cannot pick a comment character that won't be stripped from the message.

Source

Thrown at git/git.go:210

}

func CommentChar(text string) (string, error) {
	char, err := Config("core.commentchar")
	if err != nil {
		return "#", nil
	} else if char == "auto" {
		lines := strings.Split(text, "\n")
		commentCharCandidates := strings.Split("#;@!$%^&|:", "")
	candidateLoop:
		for _, candidate := range commentCharCandidates {
			for _, line := range lines {
				if strings.HasPrefix(line, candidate) {
					continue candidateLoop
				}
			}
			return candidate, nil
		}
		return "", fmt.Errorf("unable to select a comment character that is not used in the current message")
	} else {
		return char, nil
	}
}

func Show(sha string) (string, error) {
	cmd := cmd.New("git")
	cmd.Stderr = nil
	cmd.WithArg("-c").WithArg("log.showSignature=false")
	cmd.WithArg("show").WithArg("-s").WithArg("--format=%s%n%+b").WithArg(sha)

	output, err := cmd.Output()
	return strings.TrimSpace(output), err
}

func Log(sha1, sha2 string) (string, error) {
	execCmd := cmd.New("git")
	execCmd.WithArg("-c").WithArg("log.showSignature=false").WithArg("log").WithArg("--no-color")

View on GitHub (pinned to 5c547ed804)

Solutions

  1. Set an explicit core.commentChar (e.g. git config core.commentChar "#")
  2. Rephrase commit message lines so they don't all start with comment characters
  3. Check `git config core.commentChar` to understand current behavior
  4. Shorten the message/prompt so fewer leading characters collide

Example fix

// before
char, err := git.CommentChar()
// after
if err := run("git", "config", "core.commentChar", "#"); err != nil {
    return err
}
char, err := git.CommentChar()
Defensive patterns

Strategy: fallback

Validate before calling

cfg, err := exec.Command("git", "config", "core.commentChar").Output()
if err == nil && strings.TrimSpace(string(cfg)) == "auto" {
    // message uses many leading comment chars; set explicit char
    exec.Command("git", "config", "core.commentChar", "#")
}

Try / catch

char, err := git.CommentChar()
if err != nil {
    char = "#" // safe default; ensure message lines don't start with '#'
}

Prevention

When it happens

Trigger: Calling git.CommentChar() (via TestCommentChar, NewEditor) with core.commentChar=auto while the message/prompt text begins lines with all candidate characters (e.g. message full of lines starting with '#', ';', etc.).

Common situations: Commit messages containing many lines starting with common comment chars; prompt templates that already use '#' or ';' prefixes; repos configured with core.commentChar=auto on git >= 2.20 behavior changes.

Related errors


AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01). Data as JSON: /api/errors/785945be0a768928. Report an issue: GitHub.