golang/go · error

invalid time from git log: %q

Error message

invalid time from git log: %q

What it means

Thrown by gitRepo.statLocal when the commit-timestamp field (f[1], expected to be a Unix epoch integer from %ct) fails strconv.ParseInt. The %q includes the full raw git log output for diagnosis. This means git returned a recognizable first field (hash) but the second field is not a parseable integer.

Source

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

	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),
		Time:    time.Unix(t, 0).UTC(),
		Version: hash,
	}
	if !strings.HasPrefix(hash, rev) {
		info.Origin.Ref = rev
	}

	// Add tags. Output looks like:

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Clear the VCS cache: 'go clean -cache'.
  2. Run 'git fsck --full' on the affected cached repo to detect object corruption.
  3. Reinstall or upgrade git to rule out a binary bug.
  4. Check for and remove any git wrappers/aliases that alter log output.

Example fix

# before: cache has corrupted commit objects
go mod download example.com/mod
# invalid time from git log: "abc123 1523994202"
# after
go clean -cache
go mod download example.com/mod
Defensive patterns

Strategy: fallback

Validate before calling

null

Type guard

null

Try / catch

// On unparseable git timestamp, clear cache and retry
info, err := repo.Stat(ctx, rev)
if err != nil && strings.Contains(err.Error(), "invalid time 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 parses 'git log --format=%H %ct %D' output; f[1] should be the commit time as seconds-since-epoch. If git emits garbage, an empty string, or a localized/non-numeric value where the timestamp should be, ParseInt fails.

Common situations: Corrupted git object database producing garbage metadata; a custom git build or wrapper altering output format; locale issues (unlikely with %ct which is always numeric); partial object files from an interrupted operation.

Related errors


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