0

In our projects, We use policy squash merge for merging and release our project when merge release branch to master branch. one of my co-worker use no fast-forward merge and put all develop's history commits in master's history commit. I search the internet and I got the below solution:

git checkout master
git reset --hard <master commit before latest merge>
git push -f origin master

I don't like doing it because I delete the release branch. How Can I squash commit after the merge?

Alex
  • 31
  • 4

1 Answers1

0

You can only do that by changing the history. Which on master is not good thing to do. If it's last commit in master you are able to do that. But after that you need to notify whole team so they will update as soon as possible. If you are tagging and this commit has tag as well it will be removed. It might affect other tools as well.

You can use the commands you posted or checkout the last commit from the feature branch, squash it, merge to master before this PR was merged, merge it and again force push it.

Personally I'll rather leave the whole history there. Hope that the developer at least did good job commiting and the commits makes sense (atomic, etc).

For the future I'll introduce automatic way for that. Never depend on the humans, they will always make mistakes. So if you have gitlab, github then enforce the commit squash. It's possible to enforce that in almost any git solution. Also only some people should be allowed to merge and it should never be the author of the feature. This is also because of security (ASVS 1.1.1)

martin.malek
  • 2,166
  • 2
  • 19
  • 31