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: "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);

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.

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)