> ## Documentation Index
> Fetch the complete documentation index at: https://code.storage/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# restoreCommit()

> Create a commit rolling a branch back to a certain commit.

<CodeGroup>
  ```typescript TypeScript theme={null} theme={"theme":{"light":"github-light","dark":"min-dark"}}
  const reset = await repo.restoreCommit({
    targetBranch: 'main',
    expectedHeadSha: currentHeadSha, // optional safety check
    targetCommitSha: safeCommitSha,
    commitMessage: `Reset to "${safeCommitMessage}"`,
    author: { name: 'Docs Bot', email: 'docs@example.com' },
    committer: { name: 'Docs Bot', email: 'docs@example.com' },
  });

  console.log('New tip:', reset.refUpdate.newSha);
  console.log('Previous tip:', reset.refUpdate.oldSha);
  ```

  ```python Python theme={null} theme={"theme":{"light":"github-light","dark":"min-dark"}}
  reset = await repo.restore_commit(
      target_branch="main",
      target_commit_sha="safeCommitSha",
      expected_head_sha=current_head_sha,
      commit_message="Reset branch to stable build",
      author={"name": "Docs Bot", "email": "docs@example.com"},
      committer={"name": "Docs Bot", "email": "docs@example.com"},
  )

  print("New tip:", reset["ref_update"]["new_sha"])
  print("Previous tip:", reset["ref_update"]["old_sha"])
  ```

  ```go Go theme={null} theme={"theme":{"light":"github-light","dark":"min-dark"}}
  // Restore a commit into a branch
  reset, err := repo.RestoreCommit(context.Background(), storage.RestoreCommitOptions{
  	TargetBranch:    "main",
  	TargetCommitSHA: "safeCommitSha",
  	ExpectedHeadSHA: currentHeadSHA,
  	CommitMessage:   "Reset branch to stable build",
  	Author:          storage.CommitSignature{Name: "Docs Bot", Email: "docs@example.com"},
  	Committer:       &storage.CommitSignature{Name: "Docs Bot", Email: "docs@example.com"},
  })

  fmt.Println("New tip:", reset.RefUpdate.NewSHA)
  fmt.Println("Previous tip:", reset.RefUpdate.OldSHA)
  ```
</CodeGroup>

## Options

<ParamField path="targetBranch" type="string" required>
  Branch name (without `refs/heads/`) that receives the reset commit.
</ParamField>

<ParamField path="targetCommitSha" type="string" required>
  Commit SHA to reset the branch back to. Commits after this point are undone.
</ParamField>

<ParamField path="author" type="string" required>
  Provide `name` and `email` for the commit author.
</ParamField>

<ParamField path="expectedHeadSha" type="string">
  Commit SHA that must match the current tip. Use to avoid races.
</ParamField>

<ParamField path="commitMessage" type="string">
  Custom message. Defaults to `Reset <branch> to "<target subject>"`.
</ParamField>

<ParamField path="committer" type="string">
  Provide `name` and `email`. If omitted, the author identity is reused.
</ParamField>

<ParamField path="refPolicies" type="object[]">
  Ordered per-ref policy rules (`{ pattern, ops? }`) embedded in the per-call JWT. First match wins. Python: `ref_policies`. Go: `RefPolicies` with type `storage.RefPolicyList`. See the [Branch Protection guide](/docs/guides/branch-protection).
</ParamField>

## Response

<ResponseField name="commitSha" type="string">
  The SHA of the reset commit
</ResponseField>

<ResponseField name="treeSha" type="string">
  The SHA of the commit's tree object
</ResponseField>

<ResponseField name="targetBranch" type="string">
  The branch that received the reset
</ResponseField>

<ResponseField name="packBytes" type="number">
  Size of the pack in bytes
</ResponseField>

<ResponseField name="refUpdate" type="object">
  Contains `branch`, `oldSha`/`old_sha` (previous tip, `000000...` if new), and `newSha`/`new_sha`
  (reset commit)
</ResponseField>
