Git Rebase (Non-Interactive)
Since git rebase -i requires an interactive editor, use
GIT_SEQUENCE_EDITOR to supply the todo list via a script:
Updating the HEAD commit: If the commit you need to modify is already at HEAD, just use
git commit --amenddirectly. The fixup+rebase workflow below is only needed for non-HEAD commits.Squashing fixups into existing commits: Create fixup commits with
git commit --fixup=<target-hash>, then write a shell script that outputs the desired todo (withpickandfixuplines in order) and run:GIT_SEQUENCE_EDITOR=/path/to/todo-script.sh git rebase -i <base>Note:
--autosquashalone without-idoes not reorder or squash anything.Rewording commit messages: Use
git format-patchto export commits as patch files, edit the message headers in the patch files, then reapply:git format-patch <base> -o /tmp/patches/ # Edit the commit message in each /tmp/patches/000N-*.patch file # (the message is between the Subject: line and the --- line) git reset --hard <base> git am /tmp/patches/*.patch