> ## 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.

# repo.restoreCommit()

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

> [!WARNING]
>
> This page documents the earlier Code Storage SDKs: `@pierre/storage`, `pierre-storage`, and
> `code-storage-go`. New code uses the [Pierre SDK](https://code.storage/docs/sdks.md). To move code to the new SDK, use the
> [`pierre-migrate`
> skill](https://github.com/pierrecomputer/skills/tree/main/skills/pierre-migrate).

```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)
```

## Options

**targetBranch** `string` *required*

Branch name (without `refs/heads/`) that receives the reset commit.

**targetCommitSha** `string` *required*

Commit SHA to reset the branch back to. Commits after this point are undone.

**author** `string` *required*

Provide `name` and `email` for the commit author.

**expectedHeadSha** `string`

Commit SHA that must match the current tip. Use to avoid races.

**commitMessage** `string`

Custom message. Defaults to `Reset <branch> to "<target subject>"`.

**committer** `string`

Provide `name` and `email`. If omitted, the author identity is reused.

**refPolicies** `object[]`

Ordered ref policy rules (`{ pattern, ops? }`) in the JWT for this call. Code Storage uses the first rule that matches the target ref. Python: `ref_policies`. Go: `RefPolicies` with type `storage.RefPolicyList`. See [Ref Policies](https://code.storage/docs/repos/ref-policies.md).

## Response

**commitSha** `string`

The SHA of the reset commit

**treeSha** `string`

The SHA of the commit's tree object

**targetBranch** `string`

The branch that received the reset

**packBytes** `number`

Size of the pack in bytes

**refUpdate** `object`

Contains `branch`, `oldSha`/`old_sha` (previous tip, `000000...` if new), and `newSha`/`new_sha`
(reset commit)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.