How to Squash Multiple Commits into One with Git Rebase
Combine multiple messy "wip" or "fix typo" commits into a single clean, atomic commit.
git rebase -i HEAD~NStep-by-Step Execution Guide
git rebase -i HEAD~3Opens your editor displaying the last 3 commits with "pick" next to each.
# pick a1b2c3d First commit
# s d4e5f6a Second commit
# s g7h8i9j Third commitKeep the first commit as "pick", and change subsequent commits to "squash" (or "s") to merge them into the first.
:wqGit prompts you to enter a single unified commit message for all squashed changes.
Critical Pitfalls & Precautions
- β’Do not squash commits that have already been merged into a shared production branch.
Squash Commits (Rebase) - Frequently Asked Questions
Common questions about safe rollback, remote history implications, and troubleshooting.
Run "git rebase --abort". Your repository will return to the exact state it was in before starting the rebase.
Related Git Command Guides
Browse All Git RecipesUndo your most recent Git commit while keeping all your edited files staged or unstaged in your working directory.
Discard all unstaged and uncommitted file modifications and restore your working tree to the latest commit.
Rename your current local branch and update the upstream remote tracking branch on GitHub or GitLab.
Delete a branch from remote origin (GitHub, GitLab, Bitbucket) after a pull request has been merged.
Amend the commit message of your latest commit before or after pushing.
Remove files from the Git staging area (index) without losing any of your local changes.