Prerequisites
- TerminusDB running locally (install guide)
- A branch with multiple commits to squash
What you'll achieve By the end of this guide, you will have squashed multiple commits on a branch into a single commit — producing a clean, readable history.
Squashing combines multiple commits into a single commit. This is useful for cleaning up history after a series of incremental changes, before merging a feature branch back to main.
Squash a branch
Example: TypeScript
const squashBranch = async () => {
const branchName = "mybranch"
const message = "Squash: combine all feature commits"
await client.squashBranch(branchName, message)
// Verify — should show a single commit
const commits = await client.query(
TerminusClient.WOQL.lib().commits("mybranch")
)
console.log("Commits after squash:", JSON.stringify(commits.bindings, null, 2))
}After squashing, the branch has a single commit with your message:
Example: JSON
[
{
"Author": { "@type": "xsd:string", "@value": "admin" },
"Commit ID": { "@type": "xsd:string", "@value": "vn7l94v4broiaz28346mdhwtgxvvy6p" },
"Message": { "@type": "xsd:string", "@value": "Squash: combine all feature commits" },
"Parent ID": null
}
]Example: Python
client.branch = "mybranch"
message = "Squash: combine all feature commits"
result = client.squash(message)The result contains the new commit path. Reset the branch HEAD to it:
Example: Python
client.reset(result, use_path=True)Verify:
Example: Python
commits = client.log(count=5)
print("Commits after squash:", commits)curl -u admin:root -X POST \
"http://localhost:6363/api/squash/admin/mydb/local/branch/mybranch" \
-H "Content-Type: application/json" \
-d '{"commit_info": {"author": "admin", "message": "Squash: combine all feature commits"}}'After squashing, the branch contains only the final state of your data in a single commit. The individual intermediate commits are no longer accessible on this branch.