git.commits.restore

Restore a branch's files to an earlier commit, in one new commit

POST /git/api/repositories/{repoId}/restoreIAM git:PushRepositoryChanges stateDestructive

History is kept: the new commit sits on top of the branch and holds exactly the files of `commit`, so files added since are deleted and files deleted since come back. A retry is safe: when the branch already holds those files the answer is 200 with `created: false`, even if `expectedOid` is now stale.

Request syntax

POST /git/api/repositories/{repoId}/restore
{
  "branch": "string",
  "commit": "string",
  "message": "string",
  "author": "object",
  "expectedOid": "string"
}

Path parameters

  • repoIdRequired

    string

    Constraints: uuid

Request body

  • branchRequired

    string

    The branch whose files to restore; it must exist

    Constraints: 1-255 chars

  • commitRequired

    string

    The commit whose files the branch gets: a full commit id (best, a retry then means the same commit), a branch, a tag, or an abbreviated id of at least 7 characters. It must be reachable from a branch or tag of this repository

    Constraints: 1-255 chars

  • messageOptional

    string

    The commit message; `Restore to <short id>: <its subject>` when absent

    Constraints: 1-2000 chars

  • authorOptional

    object

    Record someone else as the author, for a tool committing on behalf of its user; the committer is always the caller. The caller when absent

    Constraints: JSON

  • expectedOidOptional

    string

    Refuse (409) unless the branch is still at this commit, so a restore cannot overwrite a newer save

    Constraints: /^[0-9a-f]{40}$/

Response

200 with `commitOid`, `restoredFrom` and `created` (false when the branch already held those files). 404 for an unknown commit, 422 for one that is not a commit or an ambiguous abbreviation, 409 when the branch moved past `expectedOid`, does not exist, or a protection rule says no.

A JSON response is wrapped as { "success": true, "data": … }; the CLI prints the whole body with --json.

Fields of data

  • commitOidAlways

    string

    The tip of the branch: the new commit, or the existing tip when nothing had to change
  • restoredFromAlways

    string

    The full id of the commit whose files the branch now holds
  • createdAlways

    boolean

    false when the branch already held exactly those files, so no commit was made

Checked against the handlers: every route test validates their answers against this schema.

Errors

  • 400The request does not pass the schema above. The body is { "error": …, "issues": […] }, one issue per field.
  • 401No credentials, or an access key that is unknown, revoked or expired.
  • 403The caller's policies do not allow git:PushRepository on this resource. The body names the action and the resource, and the refusal is recorded in the audit log.
  • 404The resource does not exist in your organization.

Examples

The required parameters only, with example values. Replace id and the other placeholders with your own.

dcloud git commits restore repoId --branch example --commit example

Generated from the API description, the same one the API checks requests against and the CLI is built from. MCP tool: dcloud_git_commits_restore.