Skip to main content
const reset = await repo.restoreCommit({
  targetBranch: "main",
  expectedHeadSha: currentHeadSha, // optional safety check
  targetCommitSha: safeCommitSha,
  commitMessage: `Reset to "${safeCommitMessage}"`,
  author: { name: "Docs Bot", email: "[email protected]" },
  committer: { name: "Docs Bot", email: "[email protected]" },
});

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

Options

ParameterTypeDescription
targetBranch (TypeScript)
target_branch (Python)
RequiredBranch name (without refs/heads/) that receives the reset commit.
targetCommitSha (TypeScript)
target_commit_sha (Python)
RequiredCommit SHA to reset the branch back to. Commits after this point are undone.
authorRequiredProvide name and email for the commit author.
expectedHeadSha (TypeScript)
expected_head_sha (Python)
OptionalCommit SHA that must match the current tip. Use to avoid races.
commitMessage (TypeScript)
commit_message (Python)
OptionalCustom message. Defaults to Reset <branch> to "<target subject>".
committerOptionalProvide name and email. If omitted, the author identity is reused.
The method throws a RefUpdateError when the backend rejects the reset (for example, the branch tip changed).

Response

FieldTypeDescription
commitSha (TypeScript)
commit_sha (Python)
StringThe SHA of the reset commit
treeSha (TypeScript)
tree_sha (Python)
StringThe SHA of the commit’s tree object
targetBranch (TypeScript)
target_branch (Python)
StringThe branch that received the reset
packBytes (TypeScript)
pack_bytes (Python)
NumberSize of the pack in bytes
refUpdate (TypeScript)
ref_update (Python)
ObjectContains branch, oldSha/old_sha (previous tip, 000000... if new), and newSha/new_sha (reset commit)