Git squash commit and the review of future pull requests

Viewed 94

When we do a PR with squash commit between environment branches (ex: dev and master) the next PR will ignore that the previous commit was already merged and show 2 commits to merge making the review more difficult:

enter image description here

So, one may use squash merge for feature branch > dev but not for environment branches like dev > master:

enter image description here

Are these assumptions correct? Or is there a way to make the PR ignore previous PR'd commits? (I'm using Azure DevOps)

1 Answers

The key thing to understand about "squash merge" is that it is not a merge. It's effectively a cherry-pick plus squash-rebase.

So when you have this:

    A-B-C (feature)
   /
--X (dev)

and you ask to squash feature onto dev, you get this (the commits of feature are copied onto the end of dev):

    A-B-C (feature)
   /
--X-AA-BB-CC (dev)

followed by this (the copies are squashed down to a single commit):

    A-B-C (feature)
   /
--X-D (dev)

It is true that D was created by squashing copies of A, B, and C, but there is nothing in the history that reflects that fact; indeed, there is nothing that reflects any idea that D has anything at all to do with feature. And nothing at all happened to feature — so it is still sitting there. If that isn't what you want, delete feature after the merge.

Personally, I think squash merges are a very bad idea, because they erase history. And that is the problem you are having, precisely: there is no history that anything was ever done with feature (because nothing was done with it).

Related