jesseduffield/lazygit · warning

unexpected git output

Error message

unexpected git output

What it means

GetCommitAuthor runs `git show --no-patch --pretty=format:%an%x00%ae <hash>` and splits the output on a NUL byte; the error fires when no NUL is present, i.e. the output did not contain both a name and an email separated by %x00. This happens when the commit cannot be shown (git printed an error instead) or the author fields are empty/malformed so git emits nothing before the separator.

Source

Thrown at pkg/commands/git_commands/commit.go:201

type Author struct {
	Name  string
	Email string
}

func (self *CommitCommands) GetCommitAuthor(commitHash string) (Author, error) {
	cmdArgs := NewGitCmd("show").
		Arg("--no-patch", "--pretty=format:%an%x00%ae", commitHash).
		ToArgv()

	output, err := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
	if err != nil {
		return Author{}, err
	}

	split := strings.SplitN(strings.TrimSpace(output), "\x00", 2)
	if len(split) < 2 {
		return Author{}, errors.New("unexpected git output")
	}

	author := Author{Name: split[0], Email: split[1]}
	return author, err
}

func (self *CommitCommands) GetCommitMessageFirstLine(hash string) (string, error) {
	return self.GetCommitMessagesFirstLine([]string{hash})
}

func (self *CommitCommands) GetCommitMessagesFirstLine(hashes []string) (string, error) {
	cmdArgs := NewGitCmd("show").
		Arg("--no-patch", "--pretty=format:%s").
		Arg(hashes...).
		ToArgv()

	return self.cmd.New(cmdArgs).DontLog().RunWithOutput()
}

View on GitHub (pinned to c477a2959b)

Solutions

  1. Verify the commit exists before calling: `git cat-file -e <hash>`
  2. Fix the commit's author metadata if name/email is empty (filter-repo or rebase with --reset-author)
  3. Unshallow the clone if the hash sits at a shallow boundary: `git fetch --unshallow`
Defensive patterns

Strategy: validation

Validate before calling

func commitExists(hash string) bool {
    return exec.Command("git", "cat-file", "-e", hash+"^{commit}").Run() == nil
}

if !commitExists(commitHash) {
    return Author{}, fmt.Errorf("commit %s not found", commitHash)
}
author, err := commitCmd.GetCommitAuthor(commitHash)

Try / catch

Treat this error as 'author unresolvable for this commit': skip the author display rather than aborting the whole view, and optionally fall back to parsing `git log -1 --format=%an <%ae>` which tolerates missing emails differently.

Prevention

When it happens

Trigger: Passing a hash that does not exist (typo, abbreviated collision, commit garbage-collected); an author with empty name/email (repo allowing missing ident); git printing a fatal message to stdout in some edge cases; commits from a shallow clone boundary.

Common situations: UI flows that resolve authors for commits selected in the log after a background gc/prune removed them; scripts calling GetCommitAuthor with user-supplied hashes; imported repos with malformed author metadata.

Related errors


AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15). Data as JSON: /api/errors/d8d27e33781b67bd. Report an issue: GitHub.