threads / discuss / 64637

rebasing on top of reformatted branch

Subject: rebasing on top of reformatted branch

## tl;dr

2 messages between Dec 17, 2025 and Dec 17, 2025.

replies: 1people: 2as markdown or json

Simon Richter· Dec 17, 2025, 06:33 UTC · lore
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· Dec 17, 2025, 08:56 UTC · re: Simon Richter · lore

Re: rebasing on top of reformatted branch

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

← back to recent threads