{"record":{"id":"e47aec03b67647ec","repo":"GoogleContainerTools/skaffold","slug":"unable-to-find-git-commit-w","errorCode":null,"errorMessage":"unable to find git commit: %w","messagePattern":"unable to find git commit: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/tag/git_commit.go","lineNumber":68,"sourceCode":"// NewGitCommit creates a new git commit tagger. It fails if the tagger variant is invalid.\nfunc NewGitCommit(prefix, variant string, ignoreChanges bool) (*GitCommit, error) {\n\trunGitFn, found := variants[strings.ToLower(variant)]\n\tif !found {\n\t\treturn nil, fmt.Errorf(\"%q is not a valid git tagger variant\", variant)\n\t}\n\n\treturn &GitCommit{\n\t\tprefix:        prefix,\n\t\trunGitFn:      runGitFn,\n\t\tignoreChanges: ignoreChanges,\n\t}, nil\n}\n\n// GenerateTag generates a tag from the git commit.\nfunc (t *GitCommit) GenerateTag(ctx context.Context, image latest.Artifact) (string, error) {\n\tref, err := t.runGitFn(ctx, image.Workspace)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"unable to find git commit: %w\", err)\n\t}\n\n\tref = sanitizeTag(ref)\n\n\tif !t.ignoreChanges {\n\t\tchanges, err := runGit(ctx, image.Workspace, \"status\", \".\", \"--porcelain\")\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"getting git status: %w\", err)\n\t\t}\n\n\t\tif len(changes) > 0 {\n\t\t\treturn fmt.Sprintf(\"%s%s-dirty\", t.prefix, ref), nil\n\t\t}\n\t}\n\n\treturn t.prefix + ref, nil\n}\n","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/tag/git_commit.go#L50-L86","documentation":"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:'.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n# building from extracted tarball, no .git\nskaffold build\n// after\ngit clone https://host/repo.git && cd repo && skaffold build","handlingStrategy":"validation","validationCode":"cmd := exec.Command(\"git\", \"-C\", workspace, \"rev-parse\", \"--is-inside-work-tree\")\nif err := cmd.Run(); err != nil {\n    return fmt.Errorf(\"%s is not a git repository or git is unavailable: %w\", workspace, err)\n}","typeGuard":null,"tryCatchPattern":"tag, err := tagger.GenerateTag(ctx, image)\nif err != nil {\n    if strings.Contains(err.Error(), \"unable to find git commit\") {\n        return fallback.GenerateTag(ctx, image) // e.g. dateTime tagger\n    }\n    return err\n}","preventionTips":["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"],"tags":["go","skaffold","git","tagging"],"backgroundTag":"git-repository-not-found","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}