npx skills add ...
npx skills add facebook/hermes --skill non-interactive-git-rebase
Use when needing to reorder, split, drop, or amend git commits that are not the top commit, without interactive editor access. Covers programmatic rebase via GIT_SEQUENCE_EDITOR, commit splitting with automated hunk selection, and metadata changes (author, message, dates) on any commit in a range.
npx skills add facebook/hermes --skill non-interactive-git-rebase
git rebase -i normally opens an editor for the todo list. By setting GIT_SEQUENCE_EDITOR to a command that replaces the todo file with a pre-prepared one, you can perform any interactive rebase operation — reorder, drop, squash, edit, amend — entirely from scripts.
Before any rebase, create a backup branch:
After the rebase succeeds and verification passes, do NOT delete the backup branch automatically. Always ask the user before deleting it, unless the user explicitly requested automatic cleanup. The backup is cheap to keep and the user may discover problems later.
The editor receives the todo file path as $1. Any command that overwrites that file works:
Git generates the default todo (all pick lines), then invokes cp /tmp/prepared-todo <todo-file>, which replaces it with your version. Git then executes the rewritten todo.
Extract the default todo without actually rebasing — copy it out, then fail the editor so git aborts:
The false exits non-zero, so git aborts the rebase. You have the todo file, no rebase happened.
Or build it directly from git log:
Then edit the file: reorder lines, change pick to drop/squash/edit/etc.
The --exec <cmd> flag inserts an exec <cmd> line after every pick in the todo. Combined with GIT_SEQUENCE_EDITOR=: (a no-op that succeeds, leaving the default todo unchanged), this runs a command after each commit is replayed — no editor needed.
Change author email on all commits in a range:
Change commit message pattern:
Rearrange lines in the todo file. Example — move commit abc123 to the front:
Remove lines from the todo, or change pick to drop.
NEVER use reword in the todo. The reword command opens an interactive editor for the new message, which cannot be scripted via GIT_SEQUENCE_EDITOR. Instead, use edit and amend with -m:
Change pick to squash or fixup. For squash, you also need GIT_SEQUENCE_EDITOR for the commit message editor that opens after squashing:
This requires edit in the todo. When rebase stops, you run commands to split, then continue.
Automating hunk selection with git add -p: Each y/n in the printf corresponds to a hunk in order. This works reliably when hunks are well-separated (different regions of the file). If hunks are adjacent, git may present them as one hunk, and you may need s (split) first:
Alternative — patch-based splitting (more reliable for complex cases):
After any rebase, verify the tree content is identical to before (unless you intentionally dropped commits):
| Mistake | Fix |
|---|---|
Using reword in the todo | reword opens an interactive editor. Use edit + git commit --amend -m instead |
| Todo file has wrong hashes after prior rebase | Regenerate from git log — hashes change after every rebase |
git add -p gets unexpected hunks | Hunks may merge if context overlaps. Use patch-based splitting instead |
| Deleting backup branch too early | Always ask the user before deleting. They may discover problems later |
| Operation | Command |
|---|---|
| Extract todo | GIT_SEQUENCE_EDITOR='cp $1 /tmp/default-todo && false' git rebase -i <base> |
| Reorder/drop | GIT_SEQUENCE_EDITOR="cp /tmp/prepared-todo" git rebase -i <base> |
| Reword message | Same as above, use edit in todo, then git commit --amend -m "..." + --continue |
| Squash (keep msg) | Same as above, use fixup in todo |
| Squash (edit msg) | Same as above, use squash, then handle message editor |
| Split | Same as above, use edit, then manual split + --continue |
| Bulk amend | GIT_SEQUENCE_EDITOR=: git rebase -i <base> --exec '<cmd>' |