golang/go · error

unexpected response from git log: %q

Error message

unexpected response from git log: %q

What it means

Thrown by gitRepo.statLocal when 'git log' succeeds (exit 0) but the output, after splitting on whitespace, has fewer than 2 fields. The expected format is '%H %ct %D' (hash, commit timestamp, refs). Fewer than 2 fields means the output is empty or malformed — a sentinel that git produced unexpected output.

Source

Thrown at src/cmd/go/internal/modfetch/codehost/git.go:657

	}
	return nil
}

// statLocal returns a new RevInfo describing rev in the local git repository.
// It uses version as info.Version.
func (r *gitRepo) statLocal(ctx context.Context, version, rev string) (*RevInfo, error) {
	out, err := r.runGit(ctx, "git", "-c", "log.showsignature=false", "log", "--no-decorate", "-n1", "--format=format:%H %ct %D", "--end-of-options", rev, "--")
	if err != nil {
		// Return info with Origin.RepoSum if possible to allow caching of negative lookup.
		var info *RevInfo
		if refs, err := r.loadRefs(ctx); err == nil {
			info = r.unknownRevisionInfo(refs)
		}
		return info, &UnknownRevisionError{Rev: rev}
	}
	f := strings.Fields(string(out))
	if len(f) < 2 {
		return nil, fmt.Errorf("unexpected response from git log: %q", out)
	}
	hash := f[0]
	if strings.HasPrefix(hash, version) {
		version = hash // extend to full hash
	}
	t, err := strconv.ParseInt(f[1], 10, 64)
	if err != nil {
		return nil, fmt.Errorf("invalid time from git log: %q", out)
	}

	info := &RevInfo{
		Origin: &Origin{
			VCS:  "git",
			URL:  r.remoteURL,
			Hash: hash,
		},
		Name:    hash,
		Short:   r.shortenObjectHash(hash),

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Clear the cached VCS checkout: 'go clean -cache' or 'rm -rf $(go env GOMODCACHE)/cache/vcs'.
  2. Run 'git fsck' on the local cached repo to detect corruption.
  3. Upgrade git to a current stable version.
  4. Check for git wrappers/aliases: 'type git' and 'git config --list'.

Example fix

# before: corrupted cache produces malformed log output
go get example.com/mod@v1.0.0
# unexpected response from git log: ""
# after
go clean -cache
go get example.com/mod@v1.0.0
Defensive patterns

Strategy: fallback

Validate before calling

null

Type guard

null

Try / catch

// On malformed git log output, clear the cache and retry once
info, err := repo.Stat(ctx, rev)
if err != nil && strings.Contains(err.Error(), "unexpected response from git log") {
    os.RemoveAll(filepath.Join(gomodcache, "cache/vcs"))
    info, err = repo.Stat(ctx, rev)
}
return info, err

Prevention

When it happens

Trigger: statLocal runs 'git log --format=%H %ct %D' against a revision; git returns success but the stdout is empty or a single token. This can happen with corrupted git objects, a git bug, custom git wrappers, or an object database inconsistency.

Common situations: Corrupted local git cache (loose/pack object damage); a git version with a formatting bug; a git alias or wrapper script interfering with output; interrupted clone leaving partial objects.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/5a3c4cbcc4d5379c. Report an issue: GitHub.