Squash n number of git commits together:
Git provides a tool to merge n number commits by squashing, this process is known as git squashing. You can perform this operation at any time using the Git Rebase feature like $ git rebase -i HEAD~1
command.
In this article we will show you how you can merge multiple commits as one or squashing git commits
So I have checked two commits behind in an branch using git reset --hard HEAD~2
To merge the commit on the current HEAD index use git merge --squash HEAD@{1}
As you know I checked two commits behind and now my all commits are showing as new changes in git status
. Now we only need to stage all changes and commit them as new one using git commit -m "tow commits in one"
git commit -m "Combine two commits as one"
Finally you are able to push your changes to remote repo. git push
git push