Search code examples
git

Is there any way to squash all the common commits, which is shared across all branches, in one go?


Here is a representation of my current working git tree

* 39a28d2 (origin/view-creation, view-creation) Completed views ...
* 22e9359 (origin/menu-creation, menu-creation) Created menus ...
| * ef22d1d (origin/domain-creation, domain-creation) updated selects.xml ...
|/  
* 93cef7a Updated domains ...
* b732d08 (origin/project-creation, project-creation) Created modules: contact & sales ...
* 72defa9 (origin/main, main) Basic working project
* b55de24 Initial commit : Added .gitignore
* f7e61eb Initial commit

Now i want to squash 3 commits from the very bottom, into one. I can and did interactive rebasing and squashed them in one, but have to do multiple times as all the branch, naturally, share the same commit history.

Even if it try rebasing the branches, it's still lot of work and potential merge conflicts.

Is there any way to squash it once, and then push the changes onto all the branches?


Solution

  • You should do it for one of thee branches and then rebase the other, which should be a pretty straight forward thing to do.... I could even tip you to use a script I used if you do not mess with the trees.

    https://github.com/eantoranz/git-duplicate

    Say you squashed on view-creation and got this:

    * 39a28d2' (origin/view-creation, view-creation) Completed views ...
    * 22e9359' Created menus ...
    * xxxxxx Squash up to 93cef7a
    * f7e61eb Initial commit
    

    Then, a branch like domain-creation could be "rebased" like this (assuming, again, that xxxxxx and 93cef7a have the same tree):

    ./git-duplicate 93cef7a domain-creation --onto xxxxxx
    

    Just in case, the standard way would be:

    git rebase 93cef7a domain-creation --onto xxxxxx
    

    menu-creation is a special case because it is an ancestor to view-creation so, if you did not use --update-refs when rebasing, you could do:

    git branch -f menu-creation view-creation