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

Re: rebasing on top of reformatted branch

From
KHKristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
Date
Dec 17, 2025, 08:56 UTC
Message-ID
<c0a51f7f-2c3e-43b1-9e0b-668a450b0348@app.fastmail.com>
In-Reply-To
<0e1e168e-e90c-4aba-a474-50d0df75a8e7@hogyros.de>
On Wed, Dec 17, 2025, at 07:33, Simon Richter wrote:
Show 11 quoted lines
> I need to rebase a branch on top of a version that has had automatic
> formatting applied.
>
> My usual approach for this is to create an empty extra commit after the
> branch point, then filter-branch all the commits on my branch with the
> same automatic formatting, then continue rebasing. Because the filter is
> applied to the tree, no three-way merges are performed, avoiding the
> conflicts.
>
> Is there a way to automate this in a nicer way, especially if I have
> multiple branches that need to be rebased in this way?

I haven’t tried it but git-test from git-branchless should be able to solve this.[1][2]

Show 5 quoted lines
> > git-branchless’s git test command offers a solution to quickly run
> > formatters, etc., on an entire stack of commits without causing merge
> > conflicts.
> > [...]
> >     git test run --exec 'cargo fmt --all' --strategy worktree --jobs 8

That sounded great to me when I first read it (to transform the trees per snapshot). *Obvious in hindsight* considering the trend of autoformatters in various languages.

🔗 1: https://blog.waleedkhan.name/formatting-a-commit-stack/
† 2: Not to be confused with some git-test(1) scripts that run tests per
     commit in a revision range and store failure/success

I uninstalled git-branchless because it created so many weird refs and hooks and I didn’t understand the overarching goal of the command suite. I still have hooks like this laying around. :)

    #!/bin/sh
    ## START BRANCHLESS CONFIG
    # This hook has been uninstalled.
    # Run `git branchless init` to reinstall.
    ## END BRANCHLESS CONFIG
Previous: Simon Richter
Message 2 of 2 in “rebasing on top of reformatted branch”
  1. Simon RichterDec 17, 2025
  2. Kristoffer HaugsbakkDec 17, 2025

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.