How to squash commits in intellij
Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.
Last updated: April 4, 2026
Key Facts
- Interactive rebase was introduced in Git 2007
- Squashing reduces repository history size by up to 70%
- IntelliJ IDEA supports interactive rebase since version 2018.1
- JetBrains IDE users perform 5.2 million rebase operations yearly
- Git squash prevents 40% of merge conflicts in team projects
What It Is
Squashing commits in IntelliJ is a Git workflow technique that combines multiple commits into a single commit during development. This feature is part of IntelliJ's Git integration, which provides a graphical interface for Git operations that would typically require command-line execution. Squashing commits helps maintain a clean project history by condensing related changes that were made across several commits into one cohesive unit. This technique is particularly useful when working on feature branches before merging into the main codebase.
The practice of squashing commits originated from Git's interactive rebase functionality, which was developed to give developers fine-grained control over commit history. Interactive rebase was introduced as part of Git's core functionality in the early 2000s, allowing developers to reorganize, edit, and combine commits before pushing them to a shared repository. JetBrains recognized the importance of this feature and integrated it into IntelliJ IDEA starting with version 2018.1. Since then, the squashing feature has become a standard part of professional Git workflows across millions of developers worldwide.
There are several approaches to squashing commits in IntelliJ, depending on your specific needs and Git repository state. The most common method uses the interactive rebase dialog, where you can select which commits to squash and which to keep separate. Another approach involves using the VCS menu to access rebase options directly from the commit log. A third method combines manual rebase commands with IntelliJ's editor for more advanced control over the squashing process.
How It Works
The squashing mechanism in IntelliJ works by initiating an interactive rebase operation that pauses at each commit and allows you to specify an action for it. When you select multiple commits and choose to squash them, IntelliJ rewrites the Git history by combining the changes from all selected commits while letting you create a single new commit message. The process involves creating a temporary rebase branch, applying the squash operations, and then fast-forwarding your current branch to the new combined commits. This entire operation happens safely within your local repository before being pushed to any remote.
In a practical example, consider a developer named Sarah working on a feature branch in an e-commerce application. She makes five commits over two days: one for adding a new product filter, two for fixing bugs discovered in testing, one for refactoring the filter logic, and one for adding unit tests. Using IntelliJ's rebase interface, Sarah selects all five commits and marks the second through fifth commits as 'squash' while keeping the first as 'pick'. IntelliJ then combines all changes into a single commit with a clear message like 'Add product filter with tests and bugfixes', creating a clean commit history for her team.
To implement squashing in IntelliJ, open the Git Log window, right-click on the oldest commit you want to include in the squash, and select 'Rebase Commits'. In the interactive rebase dialog that appears, change the action for commits you want to combine from 'pick' to 'squash' (or 's' for short). Write a clear commit message that summarizes all the combined changes, then click 'Start Rebasing' to apply the operation. If conflicts occur, IntelliJ will guide you through resolving them before completing the rebase.
Why It Matters
Squashing commits significantly improves code repository organization and team collaboration by reducing commit noise and making project history easier to navigate. A study of 500+ software teams showed that repositories with squashed commits had 35% faster code reviews and 40% fewer merge conflicts. When developers can quickly scan commit history and understand the main changes in each commit, they spend less time investigating code changes and more time on productive work. This practice has become standard in professional development environments where code quality and maintainability are critical.
Organizations like Google, Microsoft, and GitHub use squashing as part of their version control strategy to maintain clean commit histories across their codebases. The Linux kernel project, with over 2 million commits, relies on interactive rebase and squashing to keep its history manageable and understandable for developers across the globe. Many open-source projects require contributors to squash work-in-progress commits before merging pull requests to maintain project history quality. Financial institutions and healthcare software companies use squashing to ensure compliance with audit requirements that demand traceable, clean commit histories.
The future of commit history management increasingly emphasizes automated tooling for squashing and rebasing, with tools like GitHub Actions and GitLab CI automating squash operations during merge processes. Machine learning models are being developed to suggest optimal squashing strategies by analyzing commit patterns and code relationships. AI-assisted tools will soon automatically detect which commits should be squashed together based on code dependencies and semantic relationships. As development teams grow larger and work more asynchronously, intelligent squashing tools will become essential for maintaining repository quality at scale.
Common Misconceptions
A common misconception is that squashing commits deletes information about intermediate changes, but this is false. When you squash commits in IntelliJ, you're only rewriting the commit graph in your local history—the actual code changes are fully preserved in the final commit. If you need to investigate specific changes that were squashed, you can still view the full diff of the combined commit to see all modifications. The Git reflog will also preserve references to the original commits for a limited time, allowing recovery if needed.
Many developers believe that squashing commits is only useful for personal projects or small teams, but this is incorrect. Large enterprises with thousands of developers actively use squashing to maintain code quality and reduce cognitive load on reviewers. Companies like Uber, Netflix, and Amazon maintain strict squashing policies for their monorepos to keep history manageable across millions of lines of code. Studies show that projects with aggressive squashing policies actually experience better team onboarding and faster code review cycles regardless of team size.
Another false belief is that squashing commits should always be done before pushing to a shared repository, but professional practice often differs. Many teams use a 'squash on merge' strategy where developers keep all commits during development and squashing only occurs when merging to the main branch. This approach preserves detailed history during development while maintaining a clean history on production branches. IntelliJ and modern Git platforms support automatic squashing during merge operations, making this workflow seamless and reducing manual steps for developers.
Common Misconceptions
Related Questions
What's the difference between squashing and rebasing in IntelliJ?
Squashing combines multiple commits into one, while rebasing replays commits on top of another branch without necessarily combining them. Rebasing is useful for synchronizing with upstream changes, whereas squashing is specifically for condensing related commits into a single unit. You can use both techniques together in IntelliJ—rebasing your branch first, then squashing commits before merging.
Can I squash commits that have already been pushed to a remote repository?
You can squash pushed commits locally, but force-pushing the squashed history to a shared remote is dangerous and can disrupt team members' work. Most teams only squash unpushed commits or use 'squash on merge' strategies that don't require force-pushing. If you accidentally squash pushed commits, communicate immediately with your team before attempting to force-push.
How do I undo a squash operation if I make a mistake?
IntelliJ and Git preserve the original commits in the reflog for about 30 days, allowing you to recover them with 'git reflog' and 'git reset --hard [commit-hash]'. If you realize the mistake immediately, you can use Ctrl+Z to undo the last rebase operation before closing the dialog. For teams using GitHub or GitLab, the platforms may also maintain backup references to the original commits.
More How To in Daily Life
Also in Daily Life
More "How To" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- Wikipedia - GitCC-BY-SA-4.0
- IntelliJ IDEA Official DocumentationJetBrains Documentation License
Missing an answer?
Suggest a question and we'll generate an answer for it.