You can do this fairly easily without git rebase or git merge --squash. In this example, we'll squash the last 3 commits:

git reset --soft HEAD~3

If you also want to write the new commit message from scratch, this suffices:

git reset --soft HEAD~3
git commit -m "Squashed commit"

If you want to start editing the new commit message with a concatenation of the existing commit messages (i.e. similar to what a pick/squash/squash/…/squash git rebase -i instruction list would start you with), then you need to extract those messages and pass them to git commit:

git reset --soft HEAD~3 && 
git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"

Both of those methods squash the last three commits into a single new commit in the same way. The soft reset just re-points HEAD to the last commit that you do not want to squash. Neither the index nor the working tree are touched by the soft reset, leaving the index in the desired state for your new commit (i.e. it already has all the changes from the commits that you are about to “throw away”).

Edit Based on Comments

Because git reset and git rebase rewrite history, you must use the --force flag to push the modified branch to the remote. This is what the --force flag is meant for. You can also be extra careful and fully define your target:

git push --force-with-lease origin <branch-name>
Answer from Chris Johnsen on Stack Overflow
Top answer
1 of 16
6118

You can do this fairly easily without git rebase or git merge --squash. In this example, we'll squash the last 3 commits:

git reset --soft HEAD~3

If you also want to write the new commit message from scratch, this suffices:

git reset --soft HEAD~3
git commit -m "Squashed commit"

If you want to start editing the new commit message with a concatenation of the existing commit messages (i.e. similar to what a pick/squash/squash/…/squash git rebase -i instruction list would start you with), then you need to extract those messages and pass them to git commit:

git reset --soft HEAD~3 && 
git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"

Both of those methods squash the last three commits into a single new commit in the same way. The soft reset just re-points HEAD to the last commit that you do not want to squash. Neither the index nor the working tree are touched by the soft reset, leaving the index in the desired state for your new commit (i.e. it already has all the changes from the commits that you are about to “throw away”).

Edit Based on Comments

Because git reset and git rebase rewrite history, you must use the --force flag to push the modified branch to the remote. This is what the --force flag is meant for. You can also be extra careful and fully define your target:

git push --force-with-lease origin <branch-name>
2 of 16
3130

Use git rebase -i <after-this-commit> and replace "pick" on the second and subsequent commits with "squash" or "fixup", as described in the manual:

  • "fixup" to discard the commit message, and squash it right away.

  • "squash" to combine the commit message with the previous one, and be able to edit it before squashing.

In this example, <after-this-commit> is either the SHA1 hash or the relative location from the HEAD of the current branch from which commits are analyzed for the rebase command. For example, if the user wishes to view 5 commits from the current HEAD in the past, the command is git rebase -i HEAD~5.

🌐
Git
git-scm.com › docs › git-merge
Git - git-merge Documentation
Incorporates changes from the named commits (since the time their histories diverged from the current branch) into the current branch. This command is used by git pull to incorporate changes from another repository and can be used by hand to merge changes from one branch into another.
🌐
Reddit
reddit.com › r/git › how do i rebase multiple merge commits into a single one?
r/git on Reddit: How do I rebase multiple merge commits into a single one?
December 13, 2024 - I have this currently How do I rebase the above into this?
  • Basically "squash" multiple merge commits of different branches into one super branch and one final merge commit with all changes?

🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-merge-commits-in-git
How to Merge Commits in Git? - GeeksforGeeks
July 23, 2025 - This method allows you to merge all changes from a branch but combine them into a single commit. ... git checkout main git merge --squash feature git commit -m "Merged feature branch as a single commit"
🌐
GitHub
gist.github.com › mitchellh › 319019b1b8aac9110fcfb1862e0c97fb
Merge vs. Rebase vs. Squash · GitHub
I create merge commits more than 9 out of every 10 PRs. I also believe having more commits makes git bisect better, as long as every commit builds. I hate hate hate when I bisect a project only to land on a single squashed commit from a single PR that is like +2000/-500.
🌐
Medium
medium.com › @kyledeguzmanx › squashing-commits-how-to-maintain-git-commit-history-like-a-pro-69a9ba27ca54
Squashing Commits: How to Maintain Git Commit History Like A Pro | by Kyle DeGuzman | Medium
September 11, 2022 - After performing the reset, you can just commit all those changes under one commit. There is also git merge — squash . I have personally never used it. The first two methods I previously talked about are incredibly easy and straightforward so I usually just use those two.
🌐
Atlassian
atlassian.com › git › tutorials › using branches › git merge
Git Merge | Atlassian Git Tutorial
Git merge will combine multiple sequences of commits into one unified history. In the most frequent use cases, git merge is used to combine two branches. The following examples in this document will focus on this branch merging pattern.
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › git-squash-commits
Git Squash Commits – Squashing the Last N Commits into One Commit
March 22, 2023 - To merge the new-feature branch to main and squash the commits there, I’ll use the git merge command with the --squash flag:
🌐
YouTube
youtube.com › watch
How to use git to squash commits into a single commit. - YouTube
Sometimes you need to see how to do a git squash commit.
Published   August 22, 2024
🌐
Luke Merrett
lukemerrett.com › different-merge-types-in-git
Different Merge Types in Git
August 7, 2021 - Merge commits are often seen as messy as they are empty and only really there for historical reasons. Can be especially confusing if you are trying to revert a set of changes. Can end up having a complex graph of previous branches that’s more difficult to read · If we change our example so no new commits were made to the base branch since our branch was created, Git can do something called a “Fast Forward Merge”. This is the same as a Merge but does not create a merge commit.
🌐
Brandon Pugh's Blog
brandonpugh.com › posts › tips for creating merge commits
Tips for creating merge commits | Brandon Pugh's Blog
August 31, 2024 - Merge commits that merge a pull request are more straight forward because, these days, they’re generally created by the git hosting service so you know they only contain all the changes from that feature branch.
🌐
Continuously Merging
articles.mergify.com › what-is-the-difference-between-a-merge-commit-a-squash
What Is the Difference Between a Merge Commit & a Squash?
June 8, 2023 - There are multiple variations of this basic merging process that alter the results of the operation. However, you can generally expect merge commits to add commits from a target branch to the branch you currently have checked out. Whenever you merge in Git, you do so with a local repository.
🌐
Hatica
hatica.io › blog › squashing-git-commits
How to Squash Git Commits? Benefits & Best Practices - Hatica
June 26, 2023 - Optimize Git collaboration using commit squashing. Merge commits using real code cases for a tidier, more coherent history and enhance code clarity.
🌐
Graphite
graphite.com › guides › understanding-merge-commits-git
Understanding merge commits in Git
Unlike a rebase or a squash, a merge commit preserves the entire history of both branches, making it easier to understand the context of changes and decisions made throughout the development process.
🌐
Northerncoder
northerncoder.ca › category: code › merge multiple git commits into one
Merge multiple git commits into one - northerncoder.ca
May 8, 2019 - Merging multiple commits into one is called “squashing” in Git. If you have a number of commits you recently made but wish to squash them into one clean commit, use this command: If done from the…
🌐
TestMu AI Community
community.testmuai.com › ask a question
How can I git squash commits to combine my last N commits into a single commit? - Ask a Question - TestMu AI Community
February 12, 2025 - How can I git squash commits to combine my last N commits into a single commit? I want to merge multiple recent commits into one to keep my Git history clean. What is the correct way to git squash commits while preservi…
🌐
freeCodeCamp
forum.freecodecamp.org › freecodecamp community
How to Squash Multiple Commits Into One with Git Squash - freeCodeCamp Community - The freeCodeCamp Forum
4 weeks ago - To squash the last n commits into one, run the following command: git rebase -i HEAD~n That will open up a text-editor with something similar to the following: pick commit_1 pick commit_2 pick commit_3 ... pick commit_n ...
🌐
Keep a Changelog
keepachangelog.com › en › 1.1.0
Keep a Changelog
Using commit log diffs as changelogs is a bad idea: they're full of noise. Things like merge commits, commits with obscure titles, documentation changes, etc.
🌐
Graphite
staging-graphite-splash.vercel.app › guides › git-merge-squash
Git merge squash
Utilizing git merge --squash in your Git workflow can offer several advantages, particularly in maintaining a streamlined and manageable project history. Squash merging consolidates all changes from a feature branch into a single commit on the target branch.
🌐
GitHub
gist.github.com › gembin › e0fd1e176f978ecbf1da5baef26f5b2c
Git merge commits into one · GitHub
Save gembin/e0fd1e176f978ecbf1da5baef26f5b2c to your computer and use it in GitHub Desktop. ... In most cases, you want is just simply merge several recent commits into one.