gitgit-rebasegit-squash

How to rebase old commits (squashed in target) as empty?


We have a setup with two repositories, dev repository and deploy repository (can't change that) with rebase-only merge strategy. Initially dev repo looked like this:

   main: A -> B -> C -> D
        |______|  |______|
release:    Sq1 ->    Sq2

So main would have full linear history, and release contained squashed commits and will be rebased onto deploy repo's main. release also might have deploy-only commits, which would be rebased back from deploy, but will not be rebased onto main:

At some point squashing was removed, and only rebasing was done:

   main: A -> B -> C -> D -> E  -> F
        |______|  |______|
release:    Sq1 ->    Sq2 -> E* -> F*

So current situation:

[dev]
main: only dev commits
release: old squashed commits, new commits from main + some external commits not in main

[deploy]
main: almost like release in dev, but can contain some more external commits

Now, the problem is this: every time we rebase main onto release we need to manually skip all old main commits which were already merged but with squash. We don't want to be doing that.

My idea is to rebase them all into release but remove all changes - so that the git in the future will see that those commits were merged and will skip them automatically, leaving only new commits in the rebase. But I'm not sure how to do that. Also if there is a better way to solve this, I would be glad to hear that!


Solution

  • My idea is to rebase them all into release but remove all changes - so that the git in the future will see that those commits were merged and will skip them automatically, leaving only new commits in the rebase.

    I doubt that would work: a commit is skipped during a rebase if the same content is detected, as illustrated here.

    Now, the problem is this: every time we rebase main onto release.

    That is the issue right there: permanent branches (like main or releases) are not supposed to be rebased onto anywhere.
    There can be merge to (from feature/dev branches to them).
    You might consider merging main to release, to record a given release.

    But no rebase should be done with those branches. You can rebase a feature/dev branch on top of main, when you plan to make a pull request.