{"record":{"id":"c164953edfff4887","repo":"GitoxideLabs/gitoxide","slug":"an-unborn-history-is-required-to-create-a-root-com","errorCode":null,"errorMessage":"an unborn history is required to create a root commit","messagePattern":"an unborn history is required to create a root commit","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-tix/src/edit/create.rs","lineNumber":61,"sourceCode":"    author: Option<&gix::bstr::BStr>,\n    todo: bool,\n) -> Result<Prepared> {\n    prepare_inner(repo, parent, false, source, author, todo)\n}\n\nfn prepare_inner(\n    mut repo: gix::Repository,\n    parent: Option<ObjectId>,\n    empty: bool,\n    source: Source,\n    author_override: Option<&gix::bstr::BStr>,\n    todo: bool,\n) -> Result<Prepared> {\n    repo.workdir().context(\"creating a commit requires a worktree\")?;\n    let head = repo.head().context(\"could not read HEAD before creating a commit\")?;\n    let head_id = head.id().map(gix::Id::detach);\n    if parent.is_none() && !head.is_unborn() {\n        anyhow::bail!(\"an unborn history is required to create a root commit\");\n    }\n    if let Some(parent) = parent {\n        repo.find_commit(parent)\n            .context(\"could not find the selected parent commit\")?;\n    }\n    if parent.is_none() {\n        head.referent_name().context(\"an unborn HEAD must point to a branch\")?;\n    }\n    let editor = repo\n        .editor_command()\n        .context(\"could not prepare Git editor\")?\n        .context(\"no Git editor is available\")?;\n    let mut author = repo\n        .author()\n        .context(\"no Git author is configured\")?\n        .context(\"could not resolve the Git author\")?\n        .to_owned()\n        .context(\"could not own the Git author\")?;","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-tix/src/edit/create.rs#L43-L79","documentation":"Commit creation in tix requires an unborn HEAD when no parent commit was supplied, i.e. creating a root commit is only valid when the repository has no commits yet. If a parent is not given but HEAD points at an existing commit, the operation would silently orphan history, so it bails with this message. Supplying an explicit parent is the supported way to create non-root commits.","triggerScenarios":"Calling `Prepared::prepare`/`prepare_empty`/`prepare_from` (via `prepare_inner`) with `parent == None` while HEAD resolves to an existing commit instead of being unborn.","commonSituations":"Running a create/edit command in a repository that already has history without specifying the intended parent; confusing 'new commit' with 'amend'; scripting that drops the parent argument on non-empty repos.","solutions":["Pass the intended parent commit explicitly (e.g. the current HEAD commit) instead of relying on root-commit mode.","Use the amend workflow if the goal is to modify the existing HEAD commit.","Only create root commits in a repository with unborn HEAD (no commits yet)."],"exampleFix":"// before: parent=None on a repo with existing history -> bail\nlet prepared = create::prepare(&repo, None, ...)?;\n// after\nlet head_id = repo.head_id()?.detach();\nlet prepared = create::prepare(&repo, Some(head_id), ...)?;","handlingStrategy":"validation","validationCode":"let head = repo.head()?;\nlet is_unborn = head.is_unborn();\nif parent.is_none() && !is_unborn {\n    anyhow::bail!(\"supply an explicit parent (or use amend) on a repo with history\");\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"unborn history is required\") => {\n        // retry with current HEAD as parent\n    }\n    other => other?,\n}","preventionTips":["Always pass the intended parent commit unless you deliberately mean root-commit creation.","Check `repo.head().is_unborn()` before choosing root-commit mode.","Use the amend workflow to modify existing history rather than re-creating commits."],"tags":["git","commit","invalid-state"],"backgroundTag":"invalid-state-transition","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}