hashicorp/packer · error
Packer could not read a git SHA in directory %q: %s
Error message
Packer could not read a git SHA in directory %q: %s
What it means
getGitSHA opens the git repository in the working directory to derive the build fingerprint for HCP Packer registry metadata, reading HEAD to get the current commit SHA. This error fires when the repository exists but its HEAD cannot be read — typically an initialized git directory with no commits yet. It is surfaced through PopulateVersion; committing at least once in the directory (or running Packer outside an empty git repo) resolves it.
Source
Thrown at internal/hcp/registry/hcp.go:145
if err != nil {
return "", fmt.Errorf("Packer could not read the fingerprint from git.")
}
// The config can be used to retrieve user identity. for example,
// c.User.Email. Leaving in but commented because I'm not sure we care
// about this identity right now. - Megan
//
// c, err := r.ConfigScoped(config.GlobalScope)
// if err != nil {
// return "", fmt.Errorf("Error setting git scope", err)
// }
ref, err := r.Head()
if err != nil {
// If we get there, we're in a Git dir, but HEAD cannot be read.
//
// This may happen when there's no commit in the git dir.
return "", fmt.Errorf("Packer could not read a git SHA in directory %q: %s", baseDir, err)
}
// log.Printf("Author: %v, Commit: %v\n", c.User.Email, ref.Hash())
return ref.Hash().String(), nil
}
View on GitHub (pinned to eb36e3c3e4)
Solutions
- Make at least one commit in the template repository (`git commit --allow-empty -m init`)
- Set HCP_PACKER_BUCKET_FINGERPRINT to bypass git-based fingerprinting
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at internal/hcp/registry/hcp.go:145 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/4d2181891addc018.
Report an issue: GitHub.