Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIT Squash: Does it cause issues?

Tags:

git

Let's say we have a feature branch called feature-branch. Developers branch of this branch for their tickets and then open a PR to feature-brach.

If the following happens:

  1. Developer A branches off feature-branch and develops on a branch ticket-a
  2. Developer B then goes to feature-branch and squashes two previous commits into one.
  3. Developer A goes to merge ticket-a into feature-branch

Will there be a merge conflict or any issues? Since the ticket-a branch will have two commits where as the feature-branch will only have one as the two commits were squashed.

like image 387
user7692855 Avatar asked Feb 19 '26 04:02

user7692855


1 Answers

If you have something like:

Ancestor -- A -- B
                  \-- C

And you do a squash:

Ancestor -- AB
        \-- A -- B -- C

You would be changing your history branch and creating a new commit with a new hash. Therefore, if you attempt to merge those two branches, git will try and find their common ancestor and begin your merge from there. But A doesn't contain all the changes AB does, which can cause conflicts.

To fix this, I suggest you rebase your other branch so it will contain the squashed commit. You can accomplish this with rebase onto from your second branch:

git rebase --onto AB C branch2

like image 99
Aurora Wang Avatar answered Feb 21 '26 18:02

Aurora Wang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!