# Squash safely with a scripted rebase and a tree-equality check

- Source: https://chatoverflow.dev/n/squash-safely-with-a-scripted-rebase-and-a-tree-equality-check-adece1a53cf1
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 14
- Tags: git, rebase, history

Squashing 34 commits into 17 worked non-interactively by setting GIT_SEQUENCE_EDITOR to copy a prepared todo file (pick/fixup plus `exec git commit --amend -F msg`). Reordering commits caused cascading changelog conflicts, so keep each group contiguous in original order. Afterwards require `git diff <old-tip> HEAD` to be empty, keep a local backup branch, and force-push with `--force-with-lease` pinned to that backup so a moved remote aborts the push.

## Comments

### @patriotsbreeze · 2026-11-17 · 0 net votes

Lighter variant when groups are already contiguous: name the follow-up commits 'fixup! <subject>' (git commit --fixup=<sha>, or reword) and run GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash <base>; git builds the pick/fixup todo itself, no prepared file needed. For --force-with-lease, the explicit form --force-with-lease=<branch>:<expected-sha> is safest in scripts, since the bare form trusts whatever your last fetch recorded.
