git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Programmatically edit the git rebase sequence?

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jul 3, 2026, 13:42 UTC
Message-ID
<ake8OAIyK-ELs-fU@fruit.crustytoothpaste.net>
In-Reply-To
<akei64goQf3nFhX4@hikari>
On 2026-07-03 at 12:02:33, Matthias Beyer wrote:
Show 29 quoted lines
> Hi git people,
> 
> in a recent conversation at work, the question of how to
> programmatically edit the git-rebase sequence came up.
> 
> Example use case:
> 
> I have a branch that touches a number of files, adds some files and
> removes some files.
> When rebasing, I want to split all commits that touched a certain subset
> of files, for the clearity of the history.
> 
> I look at the output of
> 
>     git log master..mybranch --oneline --diff-filter=M -- "./subdir/*.rs"
> 
> to find all commits in that subdir that only touched the files. All of
> these commits are to be "edit"ed.
> 
> Now I fire up `git rebase -i master` and manually(!) match the list from
> above `git-log` call and find the respective commits to edit them.
> 
> Is there a way I am not aware of to do that manual step programatically?
> Something like
> 
>     git rebase -i master --edit-commits="$(git log master..mybranch --diff-filter=M --format="%H" -- "./subdir/*.rs")"
> 
> would be convenient here, although I would understand if that is too
> much clutter for the already very heavy git CLI interface :-)

Yes, such a thing exists. You want `GIT_SEQUENCE_EDITOR`, which is an `EDITOR`-like command that edits the rebase list in place. So tools like `ed`, `ex`, `sed -i`, `perl -i`, or `ruby -i` would be useful here.

So you might want something like this (untested):
    GIT_SEQUENCE_EDITOR="perl -pi -e 's/^pick ($(git log master..mybranch --diff-filter=M --format="%h" -- "./subdir/*.rs" | paste -d '\''|'\'' -s -))/edit \$1/'" \
    git rebase -i master
Note the use of `%h`, since by default the object IDs are abbreviated.

If you want something simpler, you can also write a shell script which edits the first argument in place and specify that. Arbitrary shell is allowed in `GIT_SEQUENCE_EDITOR`, much like in `EDITOR` and `VISUAL`.

I personally use this alias, which explicitly does not edit the sequence list, to automatically squash in all squash and fixup commits without prompting:

    srebase = "!f() { GIT_SEQUENCE_EDITOR=true git rebase -m -i --autosquash \"$@\"; };f"
-- 
brian m. carlson (they/them)
Toronto, Ontario, CA
Previous: Michal SuchánekNext: Matt Hunter
Message 3 of 6 in “Programmatically edit the git rebase sequence?”
  1. Matthias BeyerJul 3, 2026
  2. Michal SuchánekJul 3, 2026
  3. brian m. carlsonJul 3, 2026
  4. Matt HunterJul 3, 2026
  5. D. Ben KnobleJul 3, 2026
  6. Johannes SchindelinJul 8, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.