Reset a Branch to a Previous Commit

Open inAnthropic

Prerequisites

  • TerminusDB running locally (install guide)
  • A database with commit history

What you'll achieve By the end of this guide, you will have reset a branch to a previous commit — effectively undoing all changes made after that point.

Resetting a branch moves the HEAD pointer back to a specific commit, discarding all commits that came after it. This is like git reset --hard — use it when you want to undo recent changes.

Get the commit history

First, find the commit ID you want to reset to:

Example: TypeScript
const getHistory = async () => {
  const commits = await client.getCommitHistory()
  console.log("Commits:", commits.slice(0, 5))
}

Reset to a specific commit

Once you have a commit identifier, reset the branch HEAD:

Example: TypeScript
const resetBranch = async () => {
  const commitId = "hpl18q42dbnab4vzq8me4bg1xn8p2a0"
  await client.resetBranch("main", commitId)
  console.log("Branch reset to", commitId)
}

Reset is destructive — all commits after the target commit are discarded from the branch. If you need to preserve history while undoing changes, consider using time travel to read the old state and then insert a new corrective commit.

Next steps

  • Time travel to inspect historical states without resetting
  • Branch to experiment safely before resetting
  • Squash to clean up commit history without losing data

Was this helpful?