Squashing
Git squashing combines multiple commits into a single commit when a
branch is rebased or merged into another branch. This helps to reduce
the number of commits cluttering git log, makes navigating the commit
history easier and can reduce the number of merge conflicts.
Use Cases:
- When including a branch into the main or production branch
- When a cleaner commit history is needed
- When a branch has many commits with minor changes or work in progress commits
- When a project requires a single commit for included features and changes
Examples:
When merging a branch:
git merge --squash [branch-name]
When the branch is commited after merging all commits from the
incoming branch will be squashed into one.
When markng commits in the interactive rebase editor:
squash [commit to squash]
The marked commits will be squashed when rebasing is finalized.