Home > Enterprise >  Squash and merge VS squash and rebase
Squash and merge VS squash and rebase

Time:10-25

What is the difference between 'Squash and Merge' which is one of the option for Pull request merging and 'Squash and Rebase' which can be done by git rebase -i option?

Why people recommend 'Squash and Rebase' while 'Squash and Merge' exists?

CodePudding user response:

This is not pure cosmetics. Doing rebase allow to have the conflict resolved into the commit itself, whereas without rebasing, the merge commit can contain some diff due to the conflict.

Without rebasing you can track from where the branch has started and can allow to track the time to deliver or other things.

With visual it is easier:

Squash, merge (no rebase)

2021-09-02 17:05  0200 John doe     M─│─┐ Merge branch 'bug51' into 'release'
2021-09-02 16:51  0200 John doe     │ │ o Fix stupid bug
2021-09-02 15:50  0200 John doe     M─│─│─┐ Merge branch 'featcool' into 'release'
2021-08-20 12:05  0200 John doe     │ │ │ o Add a new cool feature
2021-09-02 15:22  0200 John doe     M─│─│─┤ Merge branch 'feat2' into 'release'
2021-09-02 14:56  0200 John doe     │ │ │ o chore: feat2
2021-09-02 10:16  0200 John doe     M─│─│─│─┐ Merge branch 'feat1' into 'release'
2021-08-31 18:28  0200 John doe     │ │ │ │ o  feature so nice

With squash, rebase and merge:

2021-09-02 17:05  0200 John doe        M─┤ Merge branch 'bug51' into 'release'
2021-09-02 16:51  0200 John doe        │ o Fix stupid bug
2021-09-02 15:50  0200 John doe        M─┤ Merge branch 'featcool' into 'release'
2021-08-20 12:05  0200 John doe        │ o Add a new cool feature
2021-09-02 15:22  0200 John doe        M─┤ Merge branch 'feat2' into 'release'
2021-09-02 14:56  0200 John doe        │ o chore: feat2
2021-09-02 10:16  0200 John doe        M─┤ Merge branch 'feat1' into 'release'
2021-08-31 18:28  0200 John doe        │ o feature so nice

With squash rebase merge (fast-forward)

2021-09-02 16:51  0200 John doe      o Fix stupid bug
2021-08-20 12:05  0200 John doe      o Add a new cool feature
2021-09-02 14:56  0200 John doe      o chore: feat2
2021-08-31 18:28  0200 John doe      o feature so nice

CodePudding user response:

I think it is to avoid having a dirty tree, as if you don't rebase before merging with main branch. And you have multiples branches, it will quickly look something like this : spaghetti tree
You will agree with me that it is very hard to see what's going on.
With rebase before merging, it will look way cleanier and will be way more easy to understand : Not spaghetti tree

  • Related