# rebasing on top of reformatted branch

2 messages from 2025-12-17 to 2025-12-17. Participants: Simon Richter, Kristoffer Haugsbakk.
Thread: https://gitlist.dev/t/64637

## Simon Richter, 2025-12-17 06:33

Subject: rebasing on top of reformatted branch
Message-ID: <0e1e168e-e90c-4aba-a474-50d0df75a8e7@hogyros.de>
URL: https://gitlist.dev/e/0e1e168e-e90c-4aba-a474-50d0df75a8e7%40hogyros.de

```
Hi,

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?

    Simon

```

## Kristoffer Haugsbakk, 2025-12-17 08:56

Subject: Re: rebasing on top of reformatted branch
Message-ID: <c0a51f7f-2c3e-43b1-9e0b-668a450b0348@app.fastmail.com>
URL: https://gitlist.dev/e/c0a51f7f-2c3e-43b1-9e0b-668a450b0348%40app.fastmail.com
In-Reply-To: <0e1e168e-e90c-4aba-a474-50d0df75a8e7@hogyros.de>

```
On Wed, Dec 17, 2025, at 07:33, Simon Richter wrote:
> 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]

> > 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

```
