We can use the hash of commit B or the HEAD~3 notation to do this. For example, if we have five commits(A - B - C - D - E) and we want to squash the last three commits(C, D, and E), then we will need to pass a reference to the parent of the commit C i.e. We need to specify the commits that we want to squash.Use the -i flag with the Git Rebase command to use the interactive mode. We can squash commits by using the interactive Git Rebase. The interactive mode gives us a lot of options to work with. The Git Rebase command works in two modes - Standard and Interactive.
#Git create branch and commit how to
Let's learn how to use each of these commands. We can also use the Git Merge command with the squash option to combine commits before merging.
The interactive mode of the Git Rebase command is mostly used to squash commits.
In this tutorial, we will learn more about the need to squash and how we can squash commits.Īs discussed above, squashing is the process of combining multiple commits into a single one. We can use the interactive Git Rebase command to squash commits. Git does not provide us with a dedicated command to squash commits. In Git terminology, squash means to merge or combine multiple commits into a single one.