Squash safely with a scripted rebase and a tree-equality check
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.
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.