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))
}Example: Python
commits = client.log(count=5)
for commit in commits:
print(f"{commit['identifier']} — {commit['message']} ({commit['author']})")Example output:
Example: JSON
{
"@id": "InitialCommit/hpl18q42dbnab4vzq8me4bg1xn8p2a0",
"@type": "InitialCommit",
"author": "system",
"identifier": "hpl18q42dbnab4vzq8me4bg1xn8p2a0",
"message": "create initial schema",
"timestamp": 1660919664.9129035
}curl -u admin:root \
"http://localhost:6363/api/log/admin/mydb/local/branch/main?count=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)
}Example: Python
commit_id = "hpl18q42dbnab4vzq8me4bg1xn8p2a0"
client.reset(commit_id)curl -u admin:root -X POST \
"http://localhost:6363/api/reset/admin/mydb/local/branch/main" \
-H "Content-Type: application/json" \
-d '{"commit_descriptor": "admin/mydb/local/commit/hpl18q42dbnab4vzq8me4bg1xn8p2a0"}'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