GoogleContainerTools/skaffold · error
unable to find git commit: %w
Error message
unable to find git commit: %w
What it means
GitCommit.GenerateTag runs the configured git command (per the variant) in the artifact's workspace to obtain the commit ref. If the git command fails — typically because the workspace is not a git repository, has no commits, or git isn't installed — the underlying error is wrapped as 'unable to find git commit:'.
Source
Thrown at pkg/skaffold/tag/git_commit.go:68
// NewGitCommit creates a new git commit tagger. It fails if the tagger variant is invalid.
func NewGitCommit(prefix, variant string, ignoreChanges bool) (*GitCommit, error) {
runGitFn, found := variants[strings.ToLower(variant)]
if !found {
return nil, fmt.Errorf("%q is not a valid git tagger variant", variant)
}
return &GitCommit{
prefix: prefix,
runGitFn: runGitFn,
ignoreChanges: ignoreChanges,
}, nil
}
// GenerateTag generates a tag from the git commit.
func (t *GitCommit) GenerateTag(ctx context.Context, image latest.Artifact) (string, error) {
ref, err := t.runGitFn(ctx, image.Workspace)
if err != nil {
return "", fmt.Errorf("unable to find git commit: %w", err)
}
ref = sanitizeTag(ref)
if !t.ignoreChanges {
changes, err := runGit(ctx, image.Workspace, "status", ".", "--porcelain")
if err != nil {
return "", fmt.Errorf("getting git status: %w", err)
}
if len(changes) > 0 {
return fmt.Sprintf("%s%s-dirty", t.prefix, ref), nil
}
}
return t.prefix + ref, nil
}
View on GitHub (pinned to a1189de023)
Solutions
- Initialize the repository (`git init && git commit`) or build from a proper git clone that includes .git
- Ensure the artifact's context/workshop path points inside the git repo root
- Install git in the CI/build image and confirm it's on PATH
- Fetch history and tags in CI: `git fetch --tags --unshallow` when using the Tags variant
Example fix
// before # building from extracted tarball, no .git skaffold build // after git clone https://host/repo.git && cd repo && skaffold build
Defensive patterns
Strategy: validation
Validate before calling
cmd := exec.Command("git", "-C", workspace, "rev-parse", "--is-inside-work-tree")
if err := cmd.Run(); err != nil {
return fmt.Errorf("%s is not a git repository or git is unavailable: %w", workspace, err)
} Try / catch
tag, err := tagger.GenerateTag(ctx, image)
if err != nil {
if strings.Contains(err.Error(), "unable to find git commit") {
return fallback.GenerateTag(ctx, image) // e.g. dateTime tagger
}
return err
} Prevention
- Always build from a git clone that includes .git and at least one commit
- Run `git fetch --tags --unshallow` in CI before building
- Install git in build containers
- Verify artifact workspace paths are inside the repo
When it happens
Trigger: GenerateTag invoked on an artifact whose image.Workspace directory is not inside a git working tree; a fresh repo with zero commits (`git rev-parse HEAD` fails); a .git folder deleted or git binary missing from PATH in the build environment.
Common situations: Building a project downloaded as a tarball/zip without .git; CI checkouts using shallow or missing fetch of tags; monorepo subdirectories where the artifact lives outside the repo root; Docker images lacking git.
Related errors
- %q is not a valid git tagger variant
- getting git status: %w
- getting tags: %w
- bad timezone provided: %q, error: %s
- parsing template: %w
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/e47aec03b67647ec.
Report an issue: GitHub.