Home > git, Interesting > Messed up your git history? Use git merge squash to clean it.

Messed up your git history? Use git merge squash to clean it.

Have you ever found yourself in a situation when you made a lot of commits with messages like fix, more fixes in the dev branch? I did. It could have been that you stayed truthful to keeping git commits as small as possible. However, this rule applies only if your small commits were fully complete and tested. Let’s be honest, such commits most probably weren’t. Apparently, you just wanted to finish this never-ending task just to get it done.

Eventually, if you are lucky and patient enough, all these fixes lead to some working code. Would you merge it master? You could, but all these commits won’t pass code review. They shouldn’t, as this would make main branch messy as well. No one will be willing to understand these commits. Moreover, no one should ever revert to these commits, because they don’t represent a stable state in a repository history. So, what should we do?

Luckily, git merge –squash is the magic command which will help us to “squash” all these commits into one. The one we will merge to main branch.

https://rokpoto.com/messed-git-history-use-git-merge-squash/

Categories: git, Interesting
  1. No comments yet.
  1. No trackbacks yet.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.