Squash Commits on a Branch

Open inAnthropic

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
  }
]

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.

Next steps

  • Branch to create a feature branch before squashing main
  • Reset to undo a squash if needed (before garbage collection)
  • Clone to share your cleaned-up branch with collaborators

Was this helpful?